2012-03-02 57 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 & "\" 
相关问题