2012-03-02 93 views
5

我想看看IIS是否安裝,並顯示一條消息和下載EXE安裝IIS如果IIS沒有安裝。但是,我很難運行一個文件,而無需指定在VB腳本的完整路徑。該路徑將是動態的,它不可能指定任何其他目錄不是「%CD%獲取當前目錄並在vbscript中運行一個文件?

我的代碼:

If WScript.Arguments.length =0 Then 
Set objShell = CreateObject("Shell.Application") 

objShell.ShellExecute "wscript.exe", Chr(34) & _ 
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1 
Else 
Dim intCounter, strSubkey 
Const HKEY_LOCAL_MACHINE = &H80000002 
strComputer = "." 

Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\default:StdRegProv") 

strKeyPath = "SOFTWARE\Microsoft" 

objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys 

intCounter=0 
For Each subkey In arrSubKeys 
If subkey="InetStp" Then 
intCounter=1 or strSubkey=subkey 
End If 

Next 
currentDirectory = left(WScript.ScriptFullName, Len(WScript.ScriptFullName))-(len(WScript.ScriptName))) 

if intCounter=0 then 
Set WSHShell = CreateObject("Wscript.Shell") 
WSHShell.Run ("\currentDirectory\noiisinstalled.exe") 
Elseif intCounter=1 then 
Wscript.Echo "IIS is Already installed - " & strSubkey 
End If 
End if 

我的問題是運行沒有iisinstalled.exe file.Whatever我想劇本找不到文件

回答

8

您可以使用Scripting.FileSystemObject獲得當前目錄。

dim fso: set fso = CreateObject("Scripting.FileSystemObject") 

' directory in which this script is currently running 
CurrentDirectory = fso.GetAbsolutePathName(".") 

以此來建立一個新的路徑,你可以使用BuildPath()功能

NewPath = fso.BuildPath(CurrentDirectory, "noiisinstalled.exe") 
+0

跑因爲我想 – deception1 2012-03-04 08:36:39

1
Set WSHShell = CreateObject("Wscript.Shell") 
sCurrentDirectory = WSHShell.CurrentDirectory & "\" 
相關問題