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?
 
I'd use VBS to read a text file a line at a time setting a string variable to the line contents (ComputerName) each time the loop is performed and exit script when the end of the list is reached?
 
%computername%

is the name of the current machine that the script is run under , if that helps
So if this script gets run on each machine it %computername% will be its own name

eg
mkdir "\\%computername%\c$\Mayer\060611licenseupdate"

If you running the script from one central location this wont help

Tho if you used this batch file with a few ammendments you could get it to set-up
your stuff then run the app afterwards
 
Last edited:
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\Licen ceValidation.dll"
psexec \\%%a -u computername\administrator regsvr32.exe /U /S LicenceValidation.dll
psexec \\%%a -u computername\administrator regsvr32.exe /S c:\Mayer\060611licenseupdate\LicenceValidation.dll \LicenceValidation.dll
)

That will run the set of commands for each line found in computers.txt
 
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
 
Did you copy and paste?
theres a rogue space in line 3 ;)

And a few more errors...
try

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 regsvr32.exe /U /S LicenceValidation.dll
psexec \\%%a -u %%ae\administrator regsvr32.exe /S c:\Mayer\060611licenseupdate\LicenceValidation.dll \LicenceValidation.dll
)
 
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
 
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
	
	'Create folder
	Set FSO = CreateObject("Scripting.FileSystemObject")
	Set objFolder = FSO.CreateFolder("\\" & strLine & "\c$\Mayer\060611licenseupdate")
	
	'Copy dll
	Set FSO = CreateObject("Scripting.FileSystemObject")
	strSource = "\\viking\users\harmanp\MM 30 licenses\Pre 440.08\LicenceValidation.dll"
	strDest = "\\" & strLine & "\c$\Mayer\060611licenseupdate\"
	FSO.CopyFile strSource ,strDest ,True
	
	'Psexec
	Set Shell = CreateObject("Wscript.Shell")
		Return = Shell.Run ("psexec \\" & strLine & " -u " & strLine & "\administrator regsvr32.exe /U /S LicenceValidation.dll", 1, true)
		Return = Shell.Run ("psexec \\" & strLine & " -u " & strLine & "\administrator regsvr32.exe /S C:\Mayer\060611licenseupdate\LicenceValidation.dll \LicenceValidation.dll", 1, true)

Loop
File.Close
WScript.Echo "Complete"
WScript.Quit

Save as *.vbs and have your list of computers, each on a new line, in list.txt in the same directory.

Should work but it is a quick effort and I can't really test properly right now! :)
 
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?
 
A[L]C;19315494 said:
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?

I have just tried unregistering a couple of random application (non system32 located) dll's by name only from command prompt (ie. just using regsvr32 -u <dll name>) and it returned as successful...!

If you wanted to do it using the path as well, it would be difficult to script unless the locations/file names were a bit more consistent (I assume inconsistency due to having to search for them on C:\)
 
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?
 
A[L]C;19315901 said:
Getting an error on line 12 of your script - file already exists.

Strange as the True is the overwrite parameter correct?

Line 12, does the folder already exist?

Just added a check for that and combined the dll copying

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
	
	strSource = "\\viking\users\harmanp\MM 30 licenses\Pre 440.08\LicenceValidation.dll"
	strDest = "\\" & strLine & "\c$\Mayer\060611licenseupdate\"
	
	'Create folder and copy dll
	Set FSO = CreateObject("Scripting.FileSystemObject")
	If  FSO.FolderExists("\\" & strLine & "\c$\Mayer\060611licenseupdate") Then
		FSO.CopyFile strSource ,strDest ,True
	Else
		Set objFolder = FSO.CreateFolder("\\" & strLine & "\c$\Mayer\060611licenseupdate")
		FSO.CopyFile strSource ,strDest ,True
	End If
	
	'Psexec (you may need to include the path to executable)
	Set Shell = CreateObject("Wscript.Shell")
		Return = Shell.Run ("psexec \\" & strLine & " -u " & strLine & "\administrator regsvr32.exe /U /S LicenceValidation.dll", 1, true)
		Return = Shell.Run ("psexec \\" & strLine & " -u " & strLine & "\administrator regsvr32.exe /S C:\Mayer\060611licenseupdate\LicenceValidation.dll \LicenceValidation.dll", 1, true)

Loop
File.Close
WScript.Echo "Complete"
WScript.Quit
 
Back
Top Bottom