2012-03-02 76 views
5

Estoy tratando de ver si IIS está instalado y mostrar un mensaje y un exe de descarga en INstall IIS si IIS no está instalado. Sin embargo, estoy teniendo dificultades para ejecutar un archivo sin especificar la ruta completa en el script vb. el camino será dinámico y que sea imposible especificar cualquier otro directorio que no sea "% cd%¿Obtiene el directorio actual y ejecuta un archivo en vbscript?

Mi código:

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 

Mi problema no se está ejecutando el file.Whatever iisinstalled.exe estoy intentando el guión no puede encontrar el archivo.

Respuesta

8

Puede obtener el directorio actual usando el Scripting.FileSystemObject.

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

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

a usar esto para construir un nuevo camino, puede utilizar la función BuildPath()

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

carreras como quería – deception1

1
Set WSHShell = CreateObject("Wscript.Shell") 
sCurrentDirectory = WSHShell.CurrentDirectory & "\" 
Cuestiones relacionadas