Script help required please

Soldato
Joined
18 Oct 2002
Posts
7,515
Location
Maidenhead
Hi all,

Right so this awful application requires a new .dll to be copied to each machine, the old one (all of which are in different folders on the remote machines) needs to be unregistered and the new dll registered using regsvr32.... so I would like to create a script to automate this. So Im thinking something along the lines of

mkdir "\\computername\c$\Mayer\060611licenseupdate"
copy "\\viking\users\harmanp\MM 30 licenses\Pre 440.08\LicenceValidation.dll" "\\computername\c$\Mayer\060611licenseupdate\LicenceValidation.dll"
psexec \\computername -u computername\administrator regsvr32.exe /U /S LicenceValidation.dll
psexec \\computername -u computername\administrator regsvr32.exe /S c:\Mayer\060611licenseupdate\LicenceValidation.dll\LicenceValidation.dll

How can I get it to replace the 'computername' for a txt list with all the computer names?
 
Thanks guys

Does anyone know if it is possible to unregister a dll without knowing the path?
 
Hmmm Im getting

Code:
        1 file(s) copied.

PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

and there it hangs
 
It doesnt seem to be continuing after the first psexec. If I add a second machine to my computers.txt then it doesnt do anything.

I'm using

for /f %%a in (computers.txt) do (
mkdir "\\%%a\c$\Mayer\060611licenseupdate"
copy "\\viking\users\harmanp\MM 30 licenses\Pre 440.08\LicenceValidation.dll" "\\%%a\c$\Mayer\060611licenseupdate\LicenceValidation.dll"
psexec \\%%a -u %%a\administrator -p password -i regsvr32.exe /U LicenceValidation.dll
psexec \\%%a -u %%a\administrator -p password -i regsvr32.exe c:\Mayer\060611licenseupdate\LicenceValidation.dll -i \LicenceValidation.dll
)
exit /b 0
 
Last edited:
When running it, even without the /S for silent, I wasnt getting any messages, just the windows bleep. I wanted to see what it was doing and adding the -i prompted the message box from regsvr32 to appear
 
ooh thanks will give it a try

i wonder if you could help with the next problem!

It seems that the machines have multiple copies of the dll. Now I'm not convinced unregistering the dll without a path will work (didnt seem to on my machine).

So I'm going to need to search the whole c drive of the remote pc for each instance of licensevalidation.dll and then unregister each copy, before i register the new one.

Is this possible via a script or am I going to have to remote on to every machine?
 
yeah. I suppose I could take a selection and see where they are, then attempt to unregister at those file locations.
 
Getting an error on line 12 of your script - file already exists.

Strange as the True is the overwrite parameter correct?
 
Thanks dude.

Easy one for you, can you please write me a script to look at the same text file, and ping the pc name. If it is not pinging, can we output the results to a text file?

Thanks again!
 
Dont worry seem to have fixed it, although not sure how lol

If you have time to do the above script that would be great :D

edit: used part of your code and an example i found... just need to work it out how to output it to a file and append, not a messagebox

Code:
'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("list.txt", 1, False)

'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")

'What to run in command line
strCommand = "ping -n 1 -w 300 " & strHost

'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)

'0 = pingable, 1 = no response
If ReturnCode = 0 Then
wscript.echo strHost & " is pingable"
Else
wscript.echo strHost & " is not pingable"
End If

Loop
File.Close
WScript.Echo "Complete"
WScript.Quit
 
Last edited:
This kinda does what I need. Would be better not to have all the stuff from the ping result, ie ping statistics, and the code at the top (The this session was run stuff) doesnt work, but lol

Code:
TheDate = Date
TheTime = Time
Const ForWriting = 2, ForAppending = 8
Set Shell = wscript.createObject("wscript.shell")
set FileSystem = CreateObject("Scripting.FileSystemObject")
Dummy = Shell.Popup ( "Building Ping File. Please Wait...",1,"Ping Automation Tool",64)
If (FileSystem.FileExists("C:\Documents and Settings\harmanp\Desktop\Pingfile.txt")) Then
Set TheFile = FileSystem.OpenTextFile("C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", ForAppending, True)
Else
Set TheFile = FileSystem.OpenTextFile("C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", ForWriting, True)
End If
TheFile.WriteBlankLines(1)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(" Ping Automation Tool")
TheFile.WriteLine("This Ping Session was run on: " & TheDate & " at " & TheTime)
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
TheFile.Close


'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("livelist.txt", 1, False)

'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")



Shell.Run "Cmd.exe /c Ping.exe -n 2 " & strHost  &" >> C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", 2,True
Shell.Run "Cmd.exe /c Echo. >> C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", 2,True
Shell.Run "Cmd.exe /c Echo ********************************** >> C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", 2,True


Loop
File.Close

Shell.Run "Notepad.exe C:\Documents and Settings\harmanp\Desktop\Pingfile.txt", 1,True

WScript.Echo "Complete"
WScript.Quit


erm, well I noticed that the bottom >> append was pointing to the wrong file, hence why I couldnt see the head text... but now I cant see the results!

Six6siX I need you!
 
Last edited:
Yay fixed it

Code:
TheDate = Date
TheTime = Time
Const ForWriting = 2, ForAppending = 8
Set Shell = wscript.createObject("wscript.shell")
set FileSystem = CreateObject("Scripting.FileSystemObject")
Dummy = Shell.Popup ( "Building Ping File. Please Wait...",1,"Ping Automation Tool",64)
If (FileSystem.FileExists("Pingfile.txt")) Then
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
Else
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForWriting, True)
End If
TheFile.WriteBlankLines(1)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(" Ping Automation Tool")
TheFile.WriteLine("This Ping Session was run on: " & TheDate & " at " & TheTime)
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
TheFile.Close


'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("livelist.txt", 1, False)

'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")



Shell.Run "Cmd.exe /c Ping.exe -n 2 " & strHost  &" >> Pingfile.txt", 2,True
Shell.Run "Cmd.exe /c Echo. >> Pingfile.txt", 2,True
Shell.Run "Cmd.exe /c Echo ********************************** >> Pingfile.txt", 2,True


Loop
File.Close

Shell.Run "Notepad.exe Pingfile.txt", 1,True

WScript.Echo "Complete"
WScript.Quit
 
I think I've done it mate, hold tight

edit:

This seems to do the job

Code:
TheDate = Date
TheTime = Time
Const ForWriting = 2, ForAppending = 8
Set Shell = wscript.createObject("wscript.shell")
set FileSystem = CreateObject("Scripting.FileSystemObject")
Dummy = Shell.Popup ( "Building Ping File. Please Wait...",1,"Ping Automation Tool",64)
If (FileSystem.FileExists("Pingfile.txt")) Then
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
Else
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForWriting, True)
End If
TheFile.WriteBlankLines(1)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(" Ping Automation Tool")
TheFile.WriteLine("This Ping Session was run on: " & TheDate & " at " & TheTime)
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
TheFile.Close


'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("livelist.txt", 1, False)

'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")


'What to run in command line
strCommand = "ping -n 1 -w 300 " & strHost

'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)

'0 = pingable, 1 = no response
If ReturnCode = 0 Then

Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(strHost & " is pingable ")
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)

Else

Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(strHost & " is not pingable ")
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
End If
TheFile.Close

Loop
File.Close

Shell.Run "Notepad.exe Pingfile.txt", 1,True

WScript.Echo "Complete"
WScript.Quit


Another edit:

So Im not opening and closing the file each loop.

Code:
TheDate = Date
TheTime = Time
Const ForWriting = 2, ForAppending = 8
Set Shell = wscript.createObject("wscript.shell")
set FileSystem = CreateObject("Scripting.FileSystemObject")
Dummy = Shell.Popup ( "Building Ping File. Please Wait...",1,"Ping Automation Tool",64)
If (FileSystem.FileExists("Pingfile.txt")) Then
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)
Else
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForWriting, True)
End If
TheFile.WriteBlankLines(1)
TheFile.WriteLine("=========================================")
TheFile.WriteLine(" Ping Automation Tool")
TheFile.WriteLine("This Ping Session was run on: " & TheDate & " at " & TheTime)
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
TheFile.Close


'Open list.txt containing computer names
'Keep list.txt in the same directory as the script file
Set FSO = CreateObject("Scripting.FileSystemObject")
Set File = FSO.OpenTextFile("livelist.txt", 1, False)
Set TheFile = FileSystem.OpenTextFile("Pingfile.txt", ForAppending, True)


'Read list file one line at a time and perform tasks
Do While File.AtEndOfStream <> True
	strLine = File.ReadLine



'Host or IP to ping
strHost = strLine

'Create shell object
Set Shell = wscript.createObject("wscript.shell")


'What to run in command line
strCommand = "ping -n 1 -w 300 " & strHost

'Run command and get return code
ReturnCode = Shell.Run(strCommand, 0, True)

'0 = pingable, 1 = no response
If ReturnCode = 0 Then


TheFile.WriteLine("=========================================")
TheFile.WriteLine(strHost & " is pingable ")
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)

Else


TheFile.WriteLine("=========================================")
TheFile.WriteLine(strHost & " is not pingable ")
TheFile.WriteLine("=========================================")
TheFile.WriteBlankLines(1)
End If


Loop
TheFile.Close
File.Close

Shell.Run "Notepad.exe Pingfile.txt", 1,True

WScript.Echo "Complete"
WScript.Quit
 
Last edited:
Not quite sure how mate.... erm

Shell.Run ("taskkill /s" & strLine & " /im scale.exe")

Something like that?

well

Set Shell1 = CreateObject("Wscript.Shell")
Shell1.Run ("taskkill /s" & strLine & " /im notepad.exe")

Didnt work :(
 
Last edited:
quick question if you are still around..... the copy, does it wait for the file to be copied, before running the register? Its going across the wan so may take a little while.

Thanks
 
Back
Top Bottom