register two dlls
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
register two dlls

 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming
Author Message
Jrex7
Guest





Posted: Tue Jan 11, 2005 1:25 am    Post subject: register two dlls Reply with quote

I need a script that will allow me to register two dll in several servers.
What I was thinking was to have a single script that will read a server name
of a text file then register one or more dll files. Then do the same on the
rest of the servers on that text file.

All the help on this task will be appreciated.
Back to top
Torgeir Bakken (MVP)
Guest





Posted: Tue Jan 11, 2005 3:24 am    Post subject: Re: register two dlls Reply with quote

Jrex7 wrote:

Quote:
I need a script that will allow me to register two dll in several servers.
What I was thinking was to have a single script that will read a server name
of a text file then register one or more dll files. Then do the same on the
rest of the servers on that text file.

All the help on this task will be appreciated.
Hi


Below is a try on this (tested only against local computer though).

A prerequisite for this script to work (in it's current version), is
that all computers are domain computers, and that the user account that
runs the script is directly or indirectly (through group membership)
member of the Administrators group on the remote computers.

I have also added a ping function to check if the computers are
online before trying to make a WMI connection to them (the WMI
connection is error handled as well).


'--------------------8<----------------------

Const ForReading = 1
Const ForWriting = 2
Const FailIfNotExist = 0
Const OpenAsASCII = 0

Set objFSO = CreateObject("Scripting.FileSystemObject")

' File with server names (one server for each line)
Set objInFile = objFSO.OpenTextFile("c:\scripts\servers.txt", _
ForReading, FailIfNotExist, OpenAsASCII)

' Results are logged to this file)
Set objOutFile = objFSO.OpenTextFile _
("c:\scripts\result.txt", ForWriting, True, OpenAsASCII)

' the DLL(s) to be registered. Environment variable can be used,
' e.g. %ProgramFiles% and %SystemRoot%
arrDLLs = Array( _
"%SystemRoot%\system32\wshext.dll", _
"%SystemRoot%\system32\jscript.dll", _
"%SystemRoot%\system32\vbscript.dll" _
)

Do Until objInFile.AtEndOfStream
strComputer = Trim(objInFile.ReadLine)
If strComputer <> "" Then
If IsConnectible(strComputer, "", "") Then

On Error Resume Next
Set oWMI = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")

If Err.Number = 0 Then
For Each strDLL In arrDLLs

' to support environment variables on the command line, use
' cmd.exe /c to launch regsvr32.exe
strCmd = "cmd.exe /c regsvr32.exe /s """ & strDLL & """"

intRC = oWMI.Get("Win32_Process").Create(strCmd, _
Null, Null, intProcessID1)

' intRC will indicate if the exe was successfully launched or not
If intRC = 0 Then
If strComputer <> strPreviousComputer Then
objOutFile.WriteLine "Regsvr32 launched on " & strComputer
' to only get one entry in the log file for each server
strPreviousComputer = strComputer
End If
Else
objOutFile.Write "Failed, could not launch Regsvr32 on " _
& strComputer & ", intRC returned error " & intRC & ", "

Select Case intRC
Case 2 : objOutFile.WriteLine "Access denied"
Case 3 : objOutFile.WriteLine "Insufficient privilege"
Case 8 : objOutFile.WriteLine "Unknown failure"
Case 9 : objOutFile.WriteLine "Path for the exe not found"
Case 21 : objOutFile.WriteLine "Invalid parameter"
Case Else : objOutFile.WriteLine "Unknown error"
End Select

' if the first try failed, no point in continuing in the
' loop of files
Exit For

End If
Next

Else
objOutFile.WriteLine "Failed, could not connect to " & strComputer
End If
Else
objOutFile.WriteLine "Failed, could not ping " & strComputer
End If
End If
Loop

objInFile.Close
objOutFile.Close
Wscript.Echo "Done"


Function IsConnectible(sHost, iPings, iTO)
' Returns True or False based on the output from ping.exe
'
' Author: Alex Angelopoulos/Torgeir Bakken
' Works an "all" WSH versions
' sHost is a hostname or IP
' iPings is number of ping attempts
' iTO is timeout in milliseconds
' if values are set to "", then defaults below used

Const OpenAsASCII = 0
Const FailIfNotExist = 0
Const ForReading = 1
Dim oShell, oFSO, sTempFile, fFile

If iPings = "" Then iPings = 2
If iTO = "" Then iTO = 750

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")

sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName

oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
& " " & sHost & ">" & sTempFile, 0 , True

Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
FailIfNotExist, OpenAsASCII)

Select Case InStr(fFile.ReadAll, "TTL=")
Case 0 IsConnectible = False
Case Else IsConnectible = True
End Select

fFile.Close
oFSO.DeleteFile(sTempFile)

End Function

'--------------------8<----------------------

--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Programming All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB