#128454 - 2004-10-27 02:22 PM
Re: Create file on remote client
|
gregglsc
Fresh Scripter
Registered: 2000-11-16
Posts: 21
Loc: USA
|
This works for me.... of course you need admin rights to access the C$ share. Note also to write an @ to the file you need to double it.
Gregg
Break on $rc=SetOption('NoVarsInStrings','on') $pc="10.198.10.4" $AllUsersDesktop ="\\"+$pc+"\c$\Documents and Settings\All Users\Desktop" $ = Open(1,$AllUsersDesktop + "\Test.bat",5) $ = WriteLine(1,"@@Echo Testing" + @CRLF) CLOSE(1)
|
|
Top
|
|
|
|
#128458 - 2004-10-29 10:17 PM
Re: Create file on remote client
|
1984
Starting to like KiXtart
Registered: 2003-08-14
Posts: 150
|
I agree with Doc, prefer Jochen way/code.
However I got some other problem .
Using WriteLine I added "Del Test.bat" to the end of successfully generated batch file. Normaly the batch file should remove it self when executed! But guess what! Nothing happens!.
I tested and moved the batch file from "All Users\Desktop" to a local user id "User\Desktop" And it worked!!!
This cannot be permission or file attribute issue, User has local admin rights on remote client as well as source client, and the only attrib option on file is set to "A"
Actually I should skip the ALLUSERSPROFILE\desktop and find a way to point to USERPROFILE\desktop instead.
But i cannot find any reg key which i could use to define the path to "current user" USERPROFILE\desktop.
The "Shell Folders" contains only "Common Desktop", and that means "ALLUSERSPROFILE\desktop"
Any ideas?
Break on $rc=SetOption('NoVarsInStrings','on') $pc="10.198.10.4" $AllUsersDesktop = '\\' + $pc + '\' + Join(Split(ReadValue('\\'+$pc+'\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Desktop'),':'),'$')
$ = Open(1,$AllUsersDesktop + "\Test.bat",5) $ = WriteLine(1,"@Echo Testing" + @CRLF) $ = WriteLine(1,"Del Test.bat" + @CRLF)
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"
|
|
Top
|
|
|
|
#128462 - 2004-11-03 05:20 PM
Re: Create file on remote client
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
When you view HKEY_USERS remotely any SID listed is currently active on the computer. Ignore the "_Classes" keys for now. You will notice that there may be one or more SIDs from different domains/SAM databases.
HKEY_USERS\S-1-5-21-82352824-854245398-839522115-1085 HKEY_USERS\S-1-5-21-24123212-1034812195-1513859470-1416
In the above examples the first SID is a local account on my laptop that is used to run a service. the second is my domain account.
You will need to read the location from each user.
\\$RemotePC\HKEY_USERS\S-1-5-21-82352824-854245398-839522115-1085\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Desktop
Then you can write your file to each user's location. If you only want to hit domain accounts, you can use SidToName() to try to resolve the SID. If the SID does NOT resolve it is from the local computer or domain that is NOT trusted. Note that on a given computer SidToName() will resolve local SID but not the SID of any remote SAM. I have Perl code in one of my DLLs that can resolve SIDs from the perspective of remote computers.
|
|
Top
|
|
|
|
#128464 - 2004-11-03 06:17 PM
Re: Create file on remote client
|
1984
Starting to like KiXtart
Registered: 2003-08-14
Posts: 150
|
Thanx to Howard, its working 
Break on If VarTypeName($pc) = 'Empty' $pc= @WKSTA EndIf
If VarTypeName($user) = 'Empty' $user= @USERID EndIf
For Each $key In fEnumKey($pc, "HKEY_USERS") Dim $acct If Left($key,3) = "S-1" AND InStr($key,"_") = 0 $acct = SIDToName($key) If $acct = '' $acct = 'Sid from unknown SAM database.' EndIf $siduid = $key + " - " + $acct If InStr($siduid,$user) $key=$key EndIf Next Exit 0
Function fEnumKey($Server, $Key) Dim $Index, $Error $Index = 0 Dim $KeyName[$Index] If $Server <> "" $Key = "\\" + $Server + "\" + $Key EndIf
If KeyExist($Key) Do $KeyName[$Index] = EnumKey($Key, $Index) $Error = @Error If NOT $Error $Index = $Index + 1 ReDim PRESERVE $KeyName[$Index] Else $Index = $Index - 1 ReDim PRESERVE $KeyName[$Index] EndIf Until $Error Else $KeyName[0] = "" Exit 2 EndIf $fEnumKey = $KeyName Exit 0 EndFunction
$rc=SetOption('NoVarsInStrings','on') $pc="10.198.10.4" $CurrentUsersDesktop = '\\' + $pc + '\' + Join(Split(ReadValue('\\'+$pc+'\HKU\'+$key+'\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Desktop'),':'),'$')
$ = Open(1,$CurrentUsersDesktop + "\Test.bat",5) $ = WriteLine(1,"@Echo Testing" + @CRLF) $ = WriteLine(1,"Del Test.bat" + @CRLF)
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"
|
|
Top
|
|
|
|
#128466 - 2004-11-03 10:46 PM
Re: Create file on remote client
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
A point of clarification. The use of HKEY_Users only shows the actively logged on accounts. Other accounts/profiles could exist on a computer.
All SIDs that have local profiles can be found here: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
|
|
Top
|
|
|
|
#128468 - 2004-11-03 11:45 PM
Re: Create file on remote client
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Well, aside from answering the question that Les posed about using the RunOnce key... here is some SILVER PLATTER code that will perform the task you've asked to do.
This code should run on all workstations remotely as long as you have Administrator rights on the system and the default Admin shares have not been disabled. Local users that have Admin rights should also be able to run it.
Code:
Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
Dim $strComputer,$UserKeys,$Key,$Profile,$wl,$cf,$CUD,$Remote,$ERR
$strComputer='some remote computer name'
$strComputer = SNVerify($strComputer)
$Profile='HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
$UserKeys=ArrayEnumKey($strComputer+$Profile)
For Each $Key In $UserKeys
$CUD=ExpandEnvironmentVars(ReadValue($strComputer+$Profile+'\'+$Key,'ProfileImagePath'))
$Remote=$strComputer+SubStr($CUD,1,1)+'$'+Right($CUD+'\Desktop',-2)
If Exist($Remote)
If Exist($Remote+'\Test.bat')
Del $Remote+'\Test.bat'
EndIf
If Open(1,$Remote+'\Test.bat' , 5 ) = 0
$wl = WriteLine( 1 , '@@Echo Off' + @CRLF )
$wl = WriteLine( 1 , 'Echo Testing' + @CRLF )
$wl = WriteLine( 1 , 'Pause ' + @CRLF)
$wl = WriteLine( 1 , 'DEL ' + '"' + $Remote+'\Test.bat' + '"' + @CRLF)
$cf = Close(1)
Else
BEEP
? 'Failed to open / create file, error code : [ ' + @ERROR + ' - ' + @SERROR + ' ]'
Get $ERR
EndIf
EndIf
Next
Function ArrayEnumKey($regsubkey)
Dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray
If Not KeyExist($regsubkey)
Exit 87
EndIf
$subkeycounter=0
Do
$currentsubkey=EnumKey($regsubkey,$subkeycounter)
If Not @ERROR
ReDim Preserve $subkeyarray[$subkeycounter]
$subkeyarray[$subkeycounter]=$currentsubkey
$subkeycounter=$subkeycounter+1
EndIf
Until @ERROR
$arrayenumkey=$subkeyarray
Exit 0
EndFunction
Function SNVerify($System, Optional $Reverse)
$SNVerify = Join(Split($System, '\'), '', 3)
$SNVerify = IIf(Not $Reverse And $SNVerify <> '', '\\' + $SNVerify + '\', $SNVerify)
Exit 0
EndFunction
|
|
Top
|
|
|
|
#128470 - 2004-11-17 11:45 PM
Re: Create file on remote client
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
No problem 1984, just remember that you asked to create this file on everyone's profiles and not just logged on users. i.e. Howard's code will only work remotely against systems that have someone logged on. The code I wrote should write to all the profiles even if the user is not logged on at the time. But if Howard's solutions handles that task you want to accomplish that's good to hear.
From Howard: Quote:
A point of clarification. The use of HKEY_Users only shows the actively logged on accounts. Other accounts/profiles could exist on a computer.
All SIDs that have local profiles can be found here: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1183 anonymous users online.
|
|
|