#189626 - 2008-09-11 10:35 PM
Re: New Runnas.exe question
[Re: Thom]
|
Glenn Barnas
KiX Supporter
   
Registered: 2003-01-28
Posts: 4402
Loc: New Jersey
|
Thom,
Start simple: Create a share (or use an existing one) and put the software and install script there. Create a "request" folder in the share where everyone has write access In you login script, place the following code:
IF InGroup("Psinstall")
If Not ReadValue('HKLM\SOFTWARE\Microsoft\PowerShell\1\','Install')
$ = WriteProfileString('\\server\share\request\' + @WKSTA + '.ini, 'REQUEST', 'POWERSHELL', @WKSTA)
EndIf
EndIf This creates an INI file in the share\request folder any time powershell is needed but not present. The section is called REQUEST, and the value is POWERSHELL. The data is the workstation name, but could be anything at all - it's usually unimportant. I used the workstation name as a convenience, so I don't have to strip the workstation name from the file name later.
Now, if someone logs in and is in the PSInstall group, and doesn't have the install registry key, it will create/update the request for that workstation by creating a small INI file on the server.
That's the first half of the process... Now you need the server side of things.
Create a script that loops forever, sleeps for 10 seconds, and looks in that folder for files by calling FileProcess. (FileProcess was stolen from LogProcess, from the Script Vault).
While 1
FileProcess()
Sleep 10
Loop
For each file found, read the REQUEST section (use EnumINI UDF) and get a list of values in that section. EnumINI will return an array of values if you call EnumINI($INIFile, 'REQUEST'). You'll only have one value now (POWERSHELL), but this give you flexibility for the future.
For Each Value in the array of values, you'll call a function that creates the install process.
For now, just print "Want to install POWERSHELL on $Computer" ?
Function FileProcess()
$_Src = '\\server\share\request\'
$_File = Dir($_Src + '*.ini') ; read the first dir entry
While Not @ERROR ; loop until no more are left
$_Requests = EnumINI($_Src + $_File, 'REQUEST')
For Each $_Request in $_Requests
$_Target = ReadProfileString($_Src + $_File, 'REQUEST', $_Request)
DoInstall($_Request, $_Target) ; call a func to schedule the install on the target
; Del $_Src + $_File
Next
$_File = Dir()
Loop
Function DoInstall($What, $Where)
'Need to install ' $What ' on computer ' $Where ?
EndFunction
At first, just run the monitor script interactively somewhere. Go log in to a computer that needs powershell. You should see the file appear, and then every 10 seconds a message on the other computer that an install is needed. Kill the monitor script, uncomment the Del line, and re-run. You should now only see one message, and the file should be deleted.
Next, you need to flesh out the DoInstall function. Ideally, you'll have an INI file with one section for each possible WHAT. It should provide the share path, batch file name, and install args. For now, stay simple, doing ..
- Copy an install.bat file to "\\$WHERE\C$\Temp"
- Use tcLib to create a task. This is right from the tcLib ReadMe file
- Use tcLib functions to run the task. It will auto-delete when done
; Initialize the library
tcInit()
; Create a simple, daily task, defining the APPlication and PaRaMeters
tcDefineTask('APP=C:\temp\install.bat PRM=-t -v')
; Set the Delete When Done flag
tcDefineTask('DWD=1')
; Set the event credentials
tcDefineTask('USR=fred PWD=FredPass')
; Create the event on the target computer
$ = tcSetEvent($WHERE, $WHAT + ' Install')
; Run the new task right now
$ = tcExecute($WHERE, $WHAT + ' Install')
You need to take this and clean it up, declare args, add comments, etc... but it should work just fine. Refer to the "Running Kix as a Service" article in the Vault for more details.
Finally.. Don't initially code for process, code for concept & logic. Don't actually do thnigs, just echo messages indicating what you want to do. When that all looks right, replace the messages with actual code to do that part of the job.
Let me know when you're ready for another nudge. Post what you have and we'll polish it. This gets asked often enough to be added to the vault, too.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|