Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script help

Status
Not open for further replies.

Briandr

MIS
Jul 11, 2003
177
US
Hi All,

I need some scripting help again. Not sure how much of this code is correct. It was put together in pieces. Right now it is erroring out when attempting to do the registry import. I also suspect the line calling the external VB script files is incorrect.

const Hidden = 0
Dim filesys
Dim strFileName
const WaitOnReturn = true
Set objNet = CreateObject("WScript.Network")
Set filesys = CreateObject("Scripting.FileSystemObject")
strCompName = objNet.ComputerName
set WshShell = CreateObject("WScript.Shell")

If left(strCompName,3) = "CMH" or left(strCompName,6) = "DMDIAB" then

If filesys.FileNotExists("C:\Program Files\Java\jre6\bin\java.dll") then
objShell.CurrentDirectory = "B:\cache"
FileSystemObject.CopyFile "B:\jre6u12.exe", "C:\Windows"
objShell.CurrentDirectory = "C:\Windows"
WshShell.Run "jre6u12.exe /s",1,True

objNetwork.MapNetworkDrive "B:", "\\cmhwaltps\e$\Program Files\Altiris\Altiris Agent\Package Delivery\{84F0ACD5-BEF6-4BF1-8923-D79B6B4F28BA}\cache"
objShell.CurrentDirectory = "B:\cache"
FileSystemObject.CopyFile "B:\davincian.ico", "C:\Windows"
SRegFile = "B:\vbsenable.reg"
objShell.Run "regedit.exe /s " Chr(34) & sRegFile & Chr(34), 0, True
strFileName = Chr(34) & "B:\DavincianL.vbs" & Chr(34)
strFileName = Chr(34) & "B:\DavincianT.vbs" & Chr(34)
Else
WshShell.Run "wscript " & strFileName, , True
End If
End If



All help is appreciated. Thank you.
 
strFileName can have only the last assignment:
Chr(34) & "B:\DavincianT.vbs" & Chr(34)
are you trying to run two vbs? or just one?
 
two vbs. Not sure if it possible to combine them. Probably can combine them. Let me know if you want to see the code.

Thanks.
 
Hi,

After messing around with the code I got most of the code working, I think. Two problems remain. The first is my registry import is not working and that is why I got it Rem'd out. The second problem is I can't set the current directory. My drive mapping works and then it errors out when attempting to set the current directory. Ideas?

const Hidden = 0
Dim filesys
Dim FSO

const WaitOnReturn = true
Set objNetwork = CreateObject("WScript.Network")
Set FileSys = CreateObject("Scripting.FileSystemObject")
strCompName = objNetwork.ComputerName
set WshShell = CreateObject("WScript.Shell")
strDomain = objNetwork.UserDomain
strUser = objNetwork.UserName

If left(strCompName,3) = "CMH" or left(strCompName,6) = "DMDIAB" then

If FileSys.FileExists("C:\Program Files\Java\jre6\bin\java.dll") Then
objNetwork.MapNetworkDrive "B:", "\\cmhwaltps\e$\Program Files\Altiris\Altiris Agent\Package Delivery\{84F0ACD5-BEF6-4BF1-8923-D79B6B4F28BA}", False, "mydomain\myusername", "mypassword"

WshShell.CurrentDirectory = "B:\cache"
FileSys.CopyFile "B:\davincian.ico", "C:\Windows"
FileSys.CopyFile "B:\vbsenable.reg", "C:\Windows"
FileSys.CopyFile "B:\DavincianL.vbs", "C:\Windows"
FileSys.CopyFile "B:\DavincianT.vbs", "C:\Windows"
WshShell.CurrentDirectory = "C:\Windows"
WshShell.Run ("cscript c:\windows\DavincianL.vbs")
WshShell.Run ("cscript c:\windows\DavincianT.vbs")

rem SRegFile = "C:\Windows\vbsenable.reg"
rem objShell.Run "regedit.exe /s " Chr(34) & sRegFile & Chr(34), 0, True

Else
WshShell.CurrentDirectory = "B:\cache"
FileSys.CopyFile "B:\jre6u12.exe", "C:\Windows"
FileSys.CopyFile "B:\davincian.ico", "C:\Windows"
FileSys.CopyFile "B:\vbsenable.reg", "C:\Windows"
FileSys.CopyFile "B:\DavincianL.vbs", "C:\Windows"
FileSys.CopyFile "B:\DavincianT.vbs", "C:\Windows"
WshShell.CurrentDirectory = "C:\Windows"
WshShell.Run ("cscript c:\windows\DavincianL.vbs")
WshShell.Run ("cscript c:\windows\DavincianT.vbs")
WshShell.Run "jre6u12.exe /s",1,True

End If
End If
 
you have set the current directory to "b:\cache"
than you're trying to copy from the root directory of "b:" - FileSys.CopyFile "B:\jre6u12.exe", "C:\Windows"
this is what you need to use:
Code:
Set objShell = CreateObject("WScript.Shell")
WScript.Echo objShell.CurrentDirectory
objShell.CurrentDirectory = "C:\Temp"
when you copy files, you really don't need to set "CurrentDirectory" if you fully qualify the path:

FileSys.CopyFile "B:\xxx\cache\jre6u12.exe", "C:\Windows"
 
objShell.Run "regedit.exe /s " [red]&[/red] Chr(34) & sRegFile & Chr(34), 0, True


I hope that helps.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hi,

I can map a drive, but I can't copy the file from the script. I am getting permission denied, 800A0046. If I open up Explorer/My Computer I can see the drive the VB script mapped and I can manually copy the file. I also verified the file don't exist on the destination drive. It would be helpful to know what the switch for overwriting an existing file would be.

objNetwork.MapNetworkDrive "B:", "\\cmhwaltps\e$\Program Files\Altiris\Altiris Agent\Package Delivery\{84F0ACD5-BEF6-4BF1-8923-D79B6B4F28BA}\cache", False, "mydomainname\myusername", "mypassword"

WshShell.CurrentDirectory = "B:\"
FileSys.CopyFile "B:\davincian.ico", "C:\Windows"

Help is appreciated. I am sure this is something stupid, which is annoying me to no end.
 
Hi,

Never mind guys. I needed a slash at the end of 'C:\Windows\'. This is why I don't write code for
a living. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top