Discussion:
!VBScript running from UNC path
(too old to reply)
BSDjunkie
2006-05-31 16:01:14 UTC
Permalink
To All:

I am running a vbscript from a network UNC path, which in turn runs an MSI file.

What I need to know is how to declare the default %INSTALL_PATH% to
plug into the VBScript.

Here is a snippet of the code I am using:

Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("\\my-server\packages\calc\current\my-app.msi", , ALL_USERS)

Is it syntatically correct to type in the full UNC path?

Or should I declare some sort of %inst% variable which will reflect the same
folder and UNC path from which the vb script will run?

I am desiring to put the vbscript and msi in the same UNC path.

Thanks for listening!

Mark Withers
maximillianx
2006-05-31 16:22:46 UTC
Permalink
I use this - seems to do the trick for me:

strScriptPath = replace(wscript.scriptfullname,"\" & wscript.scriptname,"")

msgbox "Full pathname is: " & strScriptPath

best regards,
Rob
Post by BSDjunkie
I am running a vbscript from a network UNC path, which in turn runs an MSI file.
What I need to know is how to declare the default %INSTALL_PATH% to
plug into the VBScript.
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn =
objSoftware.Install("\\my-server\packages\calc\current\my-app.msi", ,
ALL_USERS)
Is it syntatically correct to type in the full UNC path?
Or should I declare some sort of %inst% variable which will reflect the same
folder and UNC path from which the vb script will run?
I am desiring to put the vbscript and msi in the same UNC path.
Thanks for listening!
Mark Withers
BSDjunkie
2006-05-31 18:00:47 UTC
Permalink
Wow!

Thanks Rob...I'll give it a try.

Mark
Post by maximillianx
strScriptPath = replace(wscript.scriptfullname,"\" & wscript.scriptname,"")
msgbox "Full pathname is: " & strScriptPath
best regards,
Rob
Post by BSDjunkie
I am running a vbscript from a network UNC path, which in turn runs an MSI file.
What I need to know is how to declare the default %INSTALL_PATH% to
plug into the VBScript.
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn =
objSoftware.Install("\\my-server\packages\calc\current\my-app.msi", ,
ALL_USERS)
Is it syntatically correct to type in the full UNC path?
Or should I declare some sort of %inst% variable which will reflect the same
folder and UNC path from which the vb script will run?
I am desiring to put the vbscript and msi in the same UNC path.
Thanks for listening!
Mark Withers
Mark Withers
2006-05-31 19:08:46 UTC
Permalink
Rob,

I tried the code you suggested and when I try to run it with a UNC path:

cscript \\my-server\path\to\vbscript\vbscript.vbs

I get an error:

Input Error: Can not find script file "\\my-server\path\to\vbscript\vbscript.vbs"

Is there something that I can do like maybe turn on and configure Remote Scripting??

Thanks again!

Mark
Post by maximillianx
strScriptPath = replace(wscript.scriptfullname,"\" & wscript.scriptname,"")
msgbox "Full pathname is: " & strScriptPath
best regards,
Rob
Post by BSDjunkie
I am running a vbscript from a network UNC path, which in turn runs an MSI file.
What I need to know is how to declare the default %INSTALL_PATH% to
plug into the VBScript.
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn =
objSoftware.Install("\\my-server\packages\calc\current\my-app.msi", ,
ALL_USERS)
Is it syntatically correct to type in the full UNC path?
Or should I declare some sort of %inst% variable which will reflect the same
folder and UNC path from which the vb script will run?
I am desiring to put the vbscript and msi in the same UNC path.
Thanks for listening!
Mark Withers
maximillianx
2006-05-31 22:05:32 UTC
Permalink
You might try to enclose your path with quotes. Does your path have spaces
in it? Can you post your code?

In VBScript you can do it like this:

wshell.run "cscript.exe " & chr(34) & strScriptPath & "\yourscript.vbs" &
chr(34)

But without knowing exactly what your path is, I'm not sure if I'm steering
you in the right direction...!

Regards,
Rob
Post by Mark Withers
Rob,
cscript \\my-server\path\to\vbscript\vbscript.vbs
Input Error: Can not find script file
"\\my-server\path\to\vbscript\vbscript.vbs"
Is there something that I can do like maybe turn on and configure Remote Scripting??
Thanks again!
Mark
Post by maximillianx
strScriptPath = replace(wscript.scriptfullname,"\" &
wscript.scriptname,"")
msgbox "Full pathname is: " & strScriptPath
best regards,
Rob
Post by BSDjunkie
I am running a vbscript from a network UNC path, which in turn runs an
MSI
file.
What I need to know is how to declare the default %INSTALL_PATH% to
plug into the VBScript.
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn =
objSoftware.Install("\\my-server\packages\calc\current\my-app.msi", ,
ALL_USERS)
Is it syntatically correct to type in the full UNC path?
Or should I declare some sort of %inst% variable which will reflect the same
folder and UNC path from which the vb script will run?
I am desiring to put the vbscript and msi in the same UNC path.
Thanks for listening!
Mark Withers
BSDjunkie
2006-06-01 12:33:19 UTC
Permalink
Hello Rob!

Yeah I should have included more information in my first post, but I did
not realize the scope of what I am trying to do.

I am new to vbscript and am creating a vbscript to install an msi which
will be pushed out through SMS.

Here is a snippet of the code I am working on:

'Next section installs NaviCare 6.0
'sFullPath = Wscript.ScriptFullName
'sFilePath = Wscript.ScriptName
strScriptPath = replace(Wscript.ScriptFullName,Wscript.ScriptName,"NaviCare.msi")
msgbox "Full pathname is: " & strScriptPath
errReturn = objSoftware.Install(strScriptPath, , ALL_USERS)

msgbox "this is the current value of errRuturn " & errReturn

I did get it to work, when all the files were local file system objects,
but running it through a UNC path gives other issues.

Thanks again for the replies!

Mark
Post by maximillianx
You might try to enclose your path with quotes. Does your path have spaces
in it? Can you post your code?
wshell.run "cscript.exe " & chr(34) & strScriptPath & "\yourscript.vbs" &
chr(34)
But without knowing exactly what your path is, I'm not sure if I'm steering
you in the right direction...!
Regards,
Rob
Post by Mark Withers
Rob,
cscript \\my-server\path\to\vbscript\vbscript.vbs
Input Error: Can not find script file
"\\my-server\path\to\vbscript\vbscript.vbs"
Is there something that I can do like maybe turn on and configure Remote Scripting??
Thanks again!
Mark
Post by maximillianx
strScriptPath = replace(wscript.scriptfullname,"\" &
wscript.scriptname,"")
msgbox "Full pathname is: " & strScriptPath
best regards,
Rob
Post by BSDjunkie
I am running a vbscript from a network UNC path, which in turn runs an
MSI
file.
What I need to know is how to declare the default %INSTALL_PATH% to
plug into the VBScript.
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn =
objSoftware.Install("\\my-server\packages\calc\current\my-app.msi", ,
ALL_USERS)
Is it syntatically correct to type in the full UNC path?
Or should I declare some sort of %inst% variable which will reflect the same
folder and UNC path from which the vb script will run?
I am desiring to put the vbscript and msi in the same UNC path.
Thanks for listening!
Mark Withers
Mark Withers
2006-06-01 12:49:45 UTC
Permalink
Post by maximillianx
You might try to enclose your path with quotes. Does your path have spaces
in it? Can you post your code?
wshell.run "cscript.exe " & chr(34) & strScriptPath & "\yourscript.vbs" &
chr(34)
But without knowing exactly what your path is, I'm not sure if I'm steering
you in the right direction...!
Regards,
Rob
Rob,

Here is the script in it's entirety:

'On Error Resume Next
'Initial section declares all variables. Option Explicit means you must declare variables before using
them.

Option Explicit

Dim strComputer : strComputer = "."
Dim colSoftware, objSoftware, objWMIService, errReturn, wshshell, strdesktop, oshellLink, sProgramFiles,
objService, strScriptPath,regKey, regValue

Const ALL_USERS = True

' Setting all variables. This is the section where all variables are set, although
' the values are manipulated elsewhere in the script.
' The following statement removes the current version 5.2 of NaviCare.

set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Navicare Health Enterprise Navigator 5.2'")
For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next

set objService = GetObject("winmgmts:")
set objSoftware = objService.Get("Win32_Product")
set WshShell = Wscript.CreateObject("Wscript.Shell")

' Got the answer below from a new group posting. Let's hope this works!
'strScriptPath = replace(wscript.scriptfullname,"\" & wscript.scriptname,"")




'Next section installs NaviCare 6.0
'sFullPath = Wscript.ScriptFullName
'sFilePath = Wscript.ScriptName
strScriptPath = replace(Wscript.ScriptFullName,Wscript.ScriptName,"NaviCare.msi")
msgbox "Full pathname is: " & strScriptPath
errReturn = objSoftware.Install(strScriptPath, , ALL_USERS)

msgbox "this is the current value of errRuturn " & errReturn

'Finally, modify the shortcut to point to the new version of NaviCare.
set oShellLink = WshShell.CreateShortcut(strDesktop & "\NaviCare.lnk")
strDesktop = WshShell.SpecialFolders("AllUsersDesktop")
sProgramFiles = WshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")
oShellLink.TargetPath = (sProgramFiles & "\NaviCare Systems\NaviCare6.0\cpmnav32.exe")
'oShellLink.Arguments = "-ctch_ctcm_mgr:TCH-NAVIR:9999 -unavicare -zcvs"
oShellLink.IconLocation = (sProgramFiles & "\NaviCare Systems\NaviCare6.0\cpmnav32.exe")
oShellLink.Description = "NaviCare 6.0"
oShellLink.WorkingDirectory = (sProgramFiles & "\NaviCare Systems\NaviCare6.0")
oShellLink.Save

Mark
maximillianx
2006-06-05 16:50:13 UTC
Permalink
Sorry, I thought I had replied to this last week, but here is something I
noticed.

You are calling this line of code:

errReturn = objSoftware.Install(strScriptPath, , ALL_USERS)

I would probably just use the execute or run method instead -

What I would do is this:

strScriptPath = replace(Wscript.ScriptFullName,Wscript.ScriptName,"")

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")

oShell.run strScriptPath & "\NaviCare.msi", 1, true

(set above to 'false' if you do not want the script to wait until the
exe/msi is finished installing - I would leave it at 'true').

I've not much experience with the .install method, so I can't comment on it.
However, the shell .run method should work just fine for you.

Rob
Post by Mark Withers
Post by maximillianx
You might try to enclose your path with quotes. Does your path have spaces
in it? Can you post your code?
wshell.run "cscript.exe " & chr(34) & strScriptPath & "\yourscript.vbs" &
chr(34)
But without knowing exactly what your path is, I'm not sure if I'm steering
you in the right direction...!
Regards,
Rob
Rob,
'On Error Resume Next
'Initial section declares all variables. Option Explicit means you must
declare variables before using
them.
Option Explicit
Dim strComputer : strComputer = "."
Dim colSoftware, objSoftware, objWMIService, errReturn, wshshell,
strdesktop, oshellLink, sProgramFiles,
objService, strScriptPath,regKey, regValue
Const ALL_USERS = True
' Setting all variables. This is the section where all variables are set, although
' the values are manipulated elsewhere in the script.
' The following statement removes the current version 5.2 of NaviCare.
set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = 'Navicare Health
Enterprise Navigator 5.2'")
For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
set objService = GetObject("winmgmts:")
set objSoftware = objService.Get("Win32_Product")
set WshShell = Wscript.CreateObject("Wscript.Shell")
' Got the answer below from a new group posting. Let's hope this works!
'strScriptPath = replace(wscript.scriptfullname,"\" &
wscript.scriptname,"")
'Next section installs NaviCare 6.0
'sFullPath = Wscript.ScriptFullName
'sFilePath = Wscript.ScriptName
strScriptPath =
replace(Wscript.ScriptFullName,Wscript.ScriptName,"NaviCare.msi")
msgbox "Full pathname is: " & strScriptPath
errReturn = objSoftware.Install(strScriptPath, , ALL_USERS)
msgbox "this is the current value of errRuturn " & errReturn
'Finally, modify the shortcut to point to the new version of NaviCare.
set oShellLink = WshShell.CreateShortcut(strDesktop &
"\NaviCare.lnk")
strDesktop = WshShell.SpecialFolders("AllUsersDesktop")
sProgramFiles = WshShell.ExpandEnvironmentStrings("%PROGRAMFILES%")
oShellLink.TargetPath = (sProgramFiles & "\NaviCare
Systems\NaviCare6.0\cpmnav32.exe")
'oShellLink.Arguments =
"-ctch_ctcm_mgr:TCH-NAVIR:9999 -unavicare -zcvs"
oShellLink.IconLocation = (sProgramFiles & "\NaviCare
Systems\NaviCare6.0\cpmnav32.exe")
oShellLink.Description = "NaviCare 6.0"
oShellLink.WorkingDirectory = (sProgramFiles & "\NaviCare Systems\NaviCare6.0")
oShellLink.Save
Mark
Mark Withers
2006-06-05 19:08:03 UTC
Permalink
Post by maximillianx
I would probably just use the execute or run method instead -
strScriptPath = replace(Wscript.ScriptFullName,Wscript.ScriptName,"")
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run strScriptPath & "\NaviCare.msi", 1, true
Rob:

Thanks for the info!

I'll give that a try....now only one more thing.

I'm trying to search for 3 specific process names and end those
processes.

So far I have the following code:

Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery ("Select " & _
"* from WIN32_Process where Name = 'calc.exe'")
For Each objProcess in colProcessList
objProcess.Terminate()
Next

My question is, How do I add another process name to the objProcessList?

Or is the variable only for one value?

I'm still pretty new to vbscript, but am learning...

Thanks again!

Mark

Continue reading on narkive:
Loading...