Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

VB WINDOWS預設路徑

大家幾乎都灌放在C:\

但是有人也灌在D:\

我今天如果想要去執行一個程式

它是在C:\VB\lanfound.exe

可是煥在另外一台電腦不是就不行了

所以我想要執行在"WINDOWS預設磁碟:\VB.exe"

我是本身比較不會寫程式

但是我有個想法

它可以執行在有windows資料夾的磁碟中去執行檔案

我不會寫= =

不要太複雜的= =

我只是參考= =

那只是我的想法

有其他方法請提出

Update:

你可以寫詳細點嗎

我如果是要找C:\VB\lanfound.exe

系統路徑要怎寫呢

假設WINDOWS放在C:\中

Update 2:

我可能比較麻煩一點

但是你們想的我看不太懂

也沒有加註解

我乾脆把我要的

你幫我加進去好了

如果有助解釋比較好啦

原始碼在底下

我想把我的C:\換成系統的磁碟(包含WINDOWS)的磁碟

幫我寫一下吧= =

可以幫我家住解救幫忙吧

Update 3:

Private Declare Function SetCurrentDirectory Lib "kernel32" _

Alias "SetCurrentDirectoryA" (ByVal lpPathName As String) As Long

Private Sub Form_Load()

Dim tPath As String

tPath = "C:\VB\"

SetCurrentDirectory tPath

End Sub

Update 4:

看不太懂= =

2 Answers

Rating
  • 陳玄
    Lv 5
    1 decade ago
    Favorite Answer

    Const MAX_PATH = 260

    Private Declare Function GetWindowsDirectory Lib "kernel32" Alias _

    "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

    Public Function GetWinPath()

    Dim strFolder As String

    Dim lngResult As Long

    strFolder = String(MAX_PATH, 0)

    lngResult = GetWindowsDirectory(strFolder, MAX_PATH)

    If lngResult <> 0 Then

    GetWinPath = Left(strFolder, InStr(strFolder, Chr(0)) - 1)

    'GetWinPath是Windows所在的路徑

    Else

    GetWinPath = ""

    End If

    End Function

    Private Sub Command1_Click()

    s = Left(GetWinPath, 2) & "\VB\lanfound.exe"

    Shell (s)

    End Sub

    2007-12-04 08:35:50 補充:

    Private Sub Command1_Click()

    s = Left(GetWinPath, 2) & "&#92;VB&#92;lanfound.exe"

    'GetWinPath會得到C:&#92;WINDOWS(如果系統灌在C),Left(GetWinPath, 2)為左邊取兩位會得到C: ,加上 "&#92;VB&#92;lanfound.exe"就是C:&#92;VB&#92;lanfound.exe

    Shell (s)

    '執刪s, s="C:&#92;VB&#92;lanfound.exe"

    End Sub

    '這一段也可以放在FORM_LOAD,有問題歡迎到我的部落格留言。

    2007-12-04 23:19:06 補充:

    s = Left(GetWinPath, 2) & "&#92;VB&#92;lanfound.exe"

    Left(GetWinPath, 2) 為取得系統所在的磁碟(c或d就看你灌在那裡),所以s就是你所要執行的程式所在的地方

    Shell (s)

    shell為執行程式;

    最主要會用這兩行可以了

    其他程式不了解也沒關係,只要貼上去,用F8一行一行執慢慢看就了解程式在做什麼。

    2007-12-04 23:21:37 補充:

    s = Left(GetWinPath, 2) & "&#92;VB&#92;lanfound.exe"

    Shell (s)

    主要這兩行

    2007-12-04 23:23:25 補充:

    s = Left(GetWinPath, 2) & "&#92;VB&#92;lanfound.exe"(這是錯的)

    貼上去老是怪怪,自已看我原最早發表的吧,那是正確的

  • 1 decade ago

    Dim m系統路徑 As String

    m系統路徑 = Environ("WinDir")就可知道系統預設的Windows路徑

    Source(s): 忘了
Still have questions? Get your answers by asking now.