VB问题!高手进入!

来源:百度知道 编辑:UC知道 时间:2024/06/06 05:17:56
我想SHELL 系统目录下的1.exe,可是如果遇到2000,NT系统,路径就会从c:\windows\system32\1.exe 变成c:\winnt\system32\1.exe

请问如何才能实行%systen%这样的shell 方法?

方法1.用API函数获得系统目录路径,代码如下:
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long

Private Sub Command1_Click()
Dim 路径 As String, 字符串长度 As Long
路径 = Space(255)
字符串长度 = GetSystemDirectory(路径, 255)
路径 = Left$(路径, 字符串长度)
MsgBox "系统目录路径是: " & 路径
End Sub

方法2:如果你嫌API麻烦,也可以如下:
Private Sub Command2_Click()
Dim 路径 As String
If Dir("c:\windows\system32\1.exe") <> "" Then
路径 = "c:\windows\system32\1.exe"
ElseIf Dir("c:\winnt\system32\1.exe") <> "" Then
路径 = "c:\winnt\system32\1.exe"
ElseIf Dir("d:\windows\system32\1.exe") <> "" Then
路径 = "d:\windows\system32\1.exe"
ElseIf