Page 1 of 1 1
Topic Options
#128452 - 2004-10-27 01:56 PM Create file on remote client
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Thanx a lot Les.
Unfortunately its not working for me. I tried to use your code and make a bat file on remote client. Nothing happens:

Break on
$rc=SetOption('NoVarsInStrings','on')
$pc="10.198.10.4"
$AllUsersDesktop = Join(Split(ReadValue('\\'+$pc+'\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Desktop'),':'),'$')
$AllUsersDesktop ?

$ = Open(1,$AllUsersDesktop + "\Test.bat",5)
$ = WriteLine(1,"@Echo Testing" + @CRLF)
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#128453 - 2004-10-27 02:21 PM Re: Create file on remote client
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
This line

Quote:

$AllUsersDesktop = Join(Split(ReadValue('\\'+$pc+'\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Desktop'),':'),'$')




should be replaced with

Code:
 $AllUsersDesktop = '\\' + $pc + '\' + Join(Split(ReadValue('\\'+$pc+'\HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders','Common Desktop'),':'),'$') 



in order to get an unc path from it
_________________________



Top
#128454 - 2004-10-27 02:22 PM Re: Create file on remote client
gregglsc Offline
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
#128455 - 2004-10-27 02:29 PM Re: Create file on remote client
Cybex Offline
Getting the hang of it
*****

Registered: 2004-07-21
Posts: 81
Loc: Brandon, FL.
Not critical or anything but don’t take for granted that the default “C:\” share name is “C$”. It usually is but I have ran into issues with it being only “C” or something else and it caused the script to goof up…
_________________________
Common sense isn't so common.

Top
#128456 - 2004-10-28 04:40 AM Re: Create file on remote client
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
And don't take for granted that the C:\ drive is the system drive.
_________________________
There are two types of vessels, submarines and targets.

Top
#128457 - 2004-10-28 09:17 AM Re: Create file on remote client
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11629
Loc: CA
Gregg

In general you should always try to avoid HARD CODING items. It is always much better to attempt to read the value from the registry or some other method if at all possible. Your method would work for most, but better to work for ALL instead.

As for C vs C$ the only way I could see it being C is if it were a 9x or someone specifically made one for C, but the C$ share should still exist unless it has been disabled on purpose. There again, coding to work around that would be best practice as well.

Top
#128458 - 2004-10-29 10:17 PM Re: Create file on remote client
1984 Offline
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
#128459 - 2004-10-29 10:47 PM Re: Create file on remote client
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
It does not delete it cuz it does not find it. You need to provide a full path to it. I already showed you how to get the full path from the reg.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128460 - 2004-10-31 03:01 PM Re: Create file on remote client
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
ADMIN$ might be better to use.
_________________________
There are two types of vessels, submarines and targets.

Top
#128461 - 2004-11-03 04:55 PM Re: Create file on remote client
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Damn, I cannot make it work

To define a path for "current user desktop" instead of AllUsersDesktop on a remote client, I had to get it from HKEY_USERS registry and that specific users SID S-1-5-...
Not only that, I have to identify which SID in HKEY_USERS is the current logged on user.

How 2 do? Is there any other way?


_________________________
"... 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 Offline
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.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#128463 - 2004-11-03 05:45 PM Re: Create file on remote client
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You said "User has local admin rights" so then what's wrong with using the AllUserDesktop?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128464 - 2004-11-03 06:17 PM Re: Create file on remote client
1984 Offline
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
#128465 - 2004-11-03 06:29 PM Re: Create file on remote client
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Les, when the batch file was created on AllUserDesktop, it didnt remove it self once it was executed. see above.
Using Writeline i put "del test.bat" at the end of file.
Yes, user is local admin and it should work. but it didnt.
So i had to re-define and put "del C:\"Documents and Settings"\"All Users"\Desktop\test.bat". Then it worked.
However i prefer to work with current user profile instead.
_________________________
"... 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 Offline
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

_________________________
Home page: http://www.kixhelp.com/hb/

Top
#128467 - 2004-11-03 11:14 PM Re: Create file on remote client
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Not sure what the point is to put a BATch file on every user's desktop that they need to doubleclick and then it deletes itself. If you want something to just run once, why not push it to the RunOnce key and have it run automagically and then remove itself.

Does this need to run once for every user or once for every computer? Does the user really have to interact with it?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#128468 - 2004-11-03 11:45 PM Re: Create file on remote client
NTDOC Administrator Offline
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
#128469 - 2004-11-17 08:56 PM Re: Create file on remote client
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Thanx a lot NTDOC and others for your Ideas and help.

I go for Howards solution SidToName() to define the path to specific user's profile directory on remote client.

This is found here: http://home.comcast.net/~habullock/kix_solutions.htm

"List accounts logged on to local or remote (NT, W2K, XP) computers"

Its working fine for me, see post above!

Case closed :-)
_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

Top
#128470 - 2004-11-17 11:45 PM Re: Create file on remote client
NTDOC Administrator Offline
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
#128471 - 2004-11-18 02:27 AM Re: Create file on remote client
1984 Offline
Starting to like KiXtart

Registered: 2003-08-14
Posts: 150
Doc, I will test you code too, But at this point i prefer to work towards specific logged on user. However Im sure your code will be very usefull in another script im working on.

_________________________
"... Great minds talk about idea' s, average minds talk about events and samll minds talks about people...!"

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 1183 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.084 seconds in which 0.041 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