Page 1 of 1 1
Topic Options
#161144 - 2006-04-25 06:52 PM running script in remote machine
prem Offline
Lurker

Registered: 2006-04-15
Posts: 2
Hi,

Recently I have taken script_289.kix script and used it in my pc. this script basically exports all hardware and software inventory of local PC to the database (MSDE or SQL). It is working absolutely fine in the local system. Now I want to run this script in some 4 subnets within my LAN.

I have a restriction like I cannot put this in domain logon script because I do not have specific OU for these users and cannot be created.

Can anyone help me to run this script on remote machine basing on subnet I provide as input. For ex: this script.kix should scan local lan and if machine belongs to any of these subnets 192.168.1.x, 192.168.2.x, 192.168.3.x, 192.168.4.x, then it should execute the script in that machine.

please someone help in this regard.

Thanks
Prem

Top
#161145 - 2006-04-25 06:59 PM Re: running script in remote machine
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Wrong forum. This needs to go to Starters.
Top
#161146 - 2006-04-25 06:59 PM Re: running script in remote machine
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You posted to the wrong forum.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#161147 - 2006-04-25 07:25 PM Re: running script in remote machine
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
It is in the correct forum now.

Yes, you can. you will need to make a subnet enumerator, see MOAN() UDF, then ping each IP, and inventory the remote machine or RemoteExec() the app.

What method are you using to inventory the remote machine?
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#161148 - 2006-04-25 07:51 PM Re: running script in remote machine
prem Offline
Lurker

Registered: 2006-04-15
Posts: 2
Thanks Radimus for your reply. Here are my answers to your questions.
I have used below code to inventory local PC.

SetOption("Explicit","ON")

;Declare variables for ADODB Connection and RecordSet
Dim $cn, $rs, $cmd, $cmdtext, $cnstring

;Declare global variables for script
Global $sysid, $WinMgt, $LastInvDate, $RunInterval, $DateDiff, $NextRun, $Item, $i, $iValue

;Database connection string
$cnstring = "Driver={SQL Server};Server=MyServer;database=MyDatabase;uid=UserName;pwd=password"

;Creating Connection, Command and Recordset objects
$cn = CreateObject("adodb.connection")
$cmd = CreateObject("adodb.command")
$rs = CreateObject("adodb.recordset")

;Open Database Conection
$cn.connectionstring = $cnstring
$cn.Open

;Set command and recordset properties
$cmd.activeconnection = $cn
$rs.cursortype = 1
$rs.locktype = 3
$rs.activecommand = $cmd

;Check Run Settings
If KeyExist("Hkey_Local_Machine\Software\Inventory")
$LastInvDate = ReadValue("Hkey_Local_Machine\Software\Inventory","InventoryRunDate")
$RunInterval = ReadValue("Hkey_Local_Machine\Software\Inventory","InventoryRunInterval")
Else
$LastInvDate = @DATE
$RunInterval = "0"
EndIf

$DateDiff = fnSerialDate(@DATE) - fnSerialDate($LastInvDate)

If $DateDiff < $RunInterval
Exit
EndIf

?"Your IT Department is conducting an inventory of your PC."
?"Please wait as the information is collected."
SRnd(@TICKS)
$NextRun = Rnd()
$NextRun = Rnd(23)+7



WriteValue("Hkey_Local_Machine\Software\Inventory","InventoryRunDate",@DATE,"REG_SZ")
WriteValue("Hkey_Local_Machine\Software\Inventory","InventoryRunInterval",$NextRun,"REG_SZ")

;Begin Inventory Collection

;Create WMI Object
$WinMgt = GetObject("winmgmts:")
$cmdtext = "Select * from tblComputers where name = ''@WKSTA''"
$cmd.commandtext = $cmdtext
$rs.Open($cmd)

If $rs.eof = -1
$rs.addnew
EndIf
Dim $CompSys, $OpSys, $Bios, $Environment, $Drives, $CPU, $Chassis, $IP

;Update / Insert tblComputers
?"Base System Information"
$CompSys = $WinMgt.ExecQuery("Select * from Win32_ComputerSystem")
For Each $item In $CompSys
$rs.fields.item("Name").Value = $item.Name
$rs.fields.item("Manufacturer").value = $item.manufacturer
$rs.fields.item("Model").value = $item.model
$rs.fields.item("Memory").value = $item.TotalPhysicalMemory
Next
$OpSys = $WinMgt.ExecQuery("Select Caption from Win32_OperatingSystem")
For Each $item In $OpSys
$rs.fields.item("OperatingSystem").value = $item.Caption
Next
$Bios = $WinMgt.ExecQuery("Select SerialNumber from Win32_bios")
For Each $item In $bios
$rs.fields.item("SerialNumber").value = $item.serialnumber
Next
$Environment = $WinMgt.Execquery("Select VariableValue from win32_environment where name = ''stateno''")
For Each $item In $environment
$rs.fields.item("StateNumber").value = $item.VariableValue
Next
$Chassis = $WinMgt.ExecQuery("Select ChassisTypes from Win32_SystemEnclosure where tag = ''System Enclosure 0''")
For Each $item In $Chassis
$rs.fields.item("ChassisType").value = $item.ChassisTypes(0)
Next
$rs.fields.item("InvDate").Value = @DATE + " " + @TIME
$rs.update
$SysID = $rs.fields.item("ID").value
$rs.Close

;Update / Insert tblCPU
?"CPU(s)"
$cmdtext = "Select * from tblCPU where sysid = ''" + $SysID + "''"
$cmd.commandtext = $cmdtext
$rs.Open($cmd)

If $rs.eof <> -1
$rs.movefirst
While $rs.eof <> -1
$rs.delete
$rs.movenext
Loop
$rs.update
EndIf

$CPU = $WinMgt.ExecQuery("Select * from win32_processor")
For Each $item In $CPU
$rs.addnew
$rs.fields.item("sysid").value = $SysID
$rs.fields.item("ProcessorID").value = $Item.DeviceID
$rs.fields.item("Manufacturer").value = $Item.Manufacturer
$rs.fields.item("Description").value = $Item.Description
$rs.fields.item("Speed").value = $Item.MaxclockSpeed
Next
$rs.update
$rs.Close
;Update / Insert tbldiskDrive
?"Hard Disk Drive(s)"
$cmdtext = "Select * from tblDiskDrive where sysid = ''" + $SysID + "''"
$cmd.commandtext = $cmdtext
$rs.Open($cmd)

If $rs.eof <> -1
$rs.movefirst
While $rs.eof <> -1
$rs.delete
$rs.movenext
Loop
$rs.update
EndIf

$Drives = $WinMgt.ExecQuery("Select * From Win32_DiskDrive")
For Each $Item In $Drives
$rs.addNew
$rs.fields.item("sysid").value = $SysID
$rs.fields.item("DriveID").value = $item.DeviceID
$rs.fields.item("Capacity").value = $Item.size
$rs.fields.item("Manufacturer").value = $Item.Manufacturer
$rs.fields.item("Model").Value = $item.model
Next
$rs.update
$rs.Close
;Update / Insert IPConfig
?"Network Adapter(s) Configuration"
$cmdtext = "Select * from tblipconfig where sysid = ''" + $SysID + "''"
$cmd.commandtext = $cmdtext
$rs.Open($cmd)

If $rs.eof <> -1
$rs.movefirst
While $rs.eof <> -1
$rs.delete
$rs.movenext
Loop
$rs.update
EndIf

$IP = $WinMgt.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled = true")
For Each $Item In $IP
$iValue = $Item.IPAddress
For $i = 0 to Ubound($ivalue)
$rs.addnew
$rs.fields.item("sysid").value = $sysid
$rs.fields.item("nicid").value = $i
$rs.fields.item("ipaddress").value = $item.IPAddress($i)
$rs.fields.item("SubNetMask").value = $item.ipsubnet($i)
$rs.fields.item("MacAddress").value = $item.MACAddress
$rs.fields.item("ServiceName").Value = $item.ServiceName
$rs.fields.item("description").value = $item.description
Next
Next
$rs.Update
$rs.Close

;Update / Insert tblSoftware
?"Installed Software"
Dim $Index, $KeyName, $Application, $Version, $Publisher

$cmdtext = "Select * from tblsoftware where sysid = ''" + $SysID + "''"
$cmd.commandtext = $cmdtext
$rs.Open($cmd)

If $rs.eof <> -1
$rs.movefirst
While $rs.eof <> -1
$rs.delete
$rs.movenext
Loop
$rs.update
EndIf

$Index = 0
$KeyName = EnumKey("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall", $Index)
$Application = ReadValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\$KeyName", "DisplayName")
$Version = ReadValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\$KeyName", "DisplayVersion")
$Publisher = ReadValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\$KeyName", "Publisher")

While Len($keyname) > 0

If Len($Application)>0
$rs.addnew
$rs.fields.item("SysID").value = $SysID
$rs.fields.item("Application").value = $Application
$rs.fields.item("Version").value = $Version
$rs.fields.item("Publisher").value = $publisher
EndIf

$Index = 1 + $Index

$KeyName = EnumKey("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall", $Index)
$Application = ReadValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\$KeyName", "DisplayName")
$Version = ReadValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\$KeyName", "DisplayVersion")
$Publisher = ReadValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\$KeyName", "Publisher")
Loop
$rs.update
$rs.Close

?"Inventory Complete!"
?"Thank You!"
Sleep 2
Function fnSerialDate($ExpD)
Dim $z,$h,$a,$b,$c,$y,$m,$d
If InStr($ExpD,''/'')
$ExpD=Split($ExpD,''/'')
$y=Val($ExpD[0])
$m=Val($ExpD[1])
$d=Val($ExpD[2])
If $m<3
$m=$m+12
$y=$y-1
EndIf
$fnSerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
Else
$z=0+$ExpD+306
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
If $m>12
$y=$y+1
$m=$m-12
EndIf
$fnSerialDate=Right(''0000''+$y,4)+''/''+Right(''00''+$m,2)+''/''+Right(''00''+$d,2)
EndIf
EndFunction

I have used loadarrayfromfile() UDF to load each machine name from a text file

output of above UDF is loaded to ping() udf to check if the machine is active or not
If machine is active, then used remoteexec() udf to execute above kix script in remote machine.

But in this process, remoteexec() function is exiting without any error message.

any light on this problem would be appreciated.

Thanks
Prem

Top
#161149 - 2006-04-25 09:18 PM Re: running script in remote machine
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
try copying the inv script and kix32 to the remote machine then remotexec() it.

You'll have one script to enum and ping and copy the files to the target machine and a seperate code that actually does the inventory
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 561 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.063 seconds in which 0.034 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org