#145732 - 2005-08-17 02:19 AM
Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
Well, moving My Documents folder via the writevalue is working beautifully. Except, the My Documents folder doesn't reflect the change until after another logoff/logon or reboot. After the script runs, I check the registry and it shows the new mapping to be R:\ (which is what I want). But the properties of the actual My Documents folder is still set to C:\. This means that Kixtart is changing the value in the reg like it is supposed to, but the folder is not reading the reg. How do we overcome this without a reboot? I need to make a global, corporate-wide change and this could get ugly. Thanks.
|
|
Top
|
|
|
|
#145733 - 2005-08-17 03:16 AM
Re: Move My Documents via writevalue
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
use one of the process killers to kill explorer.exe and when explorer reloads the folder will be correct
enumprocess() UDF and others
|
|
Top
|
|
|
|
#145735 - 2005-08-17 05:19 PM
Re: Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
Right, but I am trying to automate this process so there is no user interaction. Everything is being driven from the script, so if I write a reboot or explorer kill in to the script, it will do that every time the user log's off and back on. What is the best way to do this so it happens one time only and no user intervention (i.e. completely silent)? Thanks.
|
|
Top
|
|
|
|
#145737 - 2005-08-17 05:39 PM
Re: Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
i am touching both of them.
|
|
Top
|
|
|
|
#145739 - 2005-08-17 05:49 PM
Re: Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
that sounds like a great idea. so, using kix, if i want to check to see that those two values in the reg were equal to R:\ and if they are, do nothing. if they are not, change them to R: and reload explorer? how would that script look? thanks!
|
|
Top
|
|
|
|
#145741 - 2005-08-17 06:02 PM
Re: Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
hmmm, i'm not sure what that is, but i'm all ears!
|
|
Top
|
|
|
|
#145742 - 2005-08-17 06:14 PM
Re: Move My Documents via writevalue
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Something like this. !! UNTESTED !!
Code:
$rc = ReadValue ("subkey", "entry")
If $rc <> "R:\" WriteValue ("subkey", "entry", "expression", "data type") $kill= EnumProcess("explorer.exe",1) Else ?"No changes needed skipping to end." EndIf ; ;Function EnumProcess($exe, optional $terminate, optional $Computer) ; ;To enumerate OR kill specific processes ; ;$exe: the process name OR numeric PID ;$terminate: null/notnull value to terminate the specified process(es) ;$Computer: the PC to Execute against. Null = local PC ; ;returns an array of PIDs (pipe seperated), If $exe is a process name ; ;To Return the pid of setup.exe ;$pid= EnumProcess("setup.exe") ; ;to terminate all running Internet Explorer windows ;$kill= EnumProcess("iexplore.exe",1) ; ;To terminate a specific exe by it's PID ;$pid=694 ;$kill=EnumProcess($pid,1) ; Function EnumProcess($exe, optional $terminate, optional $Computer) Dim $winmgmts, $ExecQuery, $Process, $id If NOT $computer $computer=@wksta EndIf $winmgmts="winmgmts:{impersonationLevel=impersonate}!//$COMPUTER" Select Case Val($exe)>0 $ExecQuery="select * from Win32_Process where ProcessId='$exe'" $GetObject=GetObject($winmgmts).ExecQuery($ExecQuery) For Each $Process in $GetObject If $terminate $=$Process.Terminate EndIf $EnumProcess = $Process.name Next $GetObject='' Case VarType($exe)=8 $ExecQuery="select * from Win32_Process where Name='$exe'" $GetObject=GetObject($winmgmts).ExecQuery($ExecQuery) For Each $Process in $GetObject If $terminate $=$Process.Terminate EndIf $id=$Process.ProcessId $EnumProcess = "$Id" + "|" + "$EnumProcess" Next $EnumProcess=Left($EnumProcess,Len($EnumProcess)-1) $GetObject='' Case 1 Exit 1 EndSelect EndFunction
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
#145744 - 2005-08-17 06:57 PM
Re: Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
hi, since i am a beginner at best with kix scripts, i totally understand what the first part of the script is doing. but what is all the code starting with the comments doing? btw, thanks a million. you are awesome and this will be a lifesaver!
|
|
Top
|
|
|
|
#145745 - 2005-08-17 08:44 PM
Re: Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
it seems as if maybe the stuff after the comments needs to go before the first part, since that is where the enumprocess function is defined. right?
|
|
Top
|
|
|
|
#145747 - 2005-08-17 08:58 PM
Re: Move My Documents via writevalue
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Nope.
The stuff after the commented lines is a UDF (User Defined Function). This adds functionality to kix that is not and does not have to be included into kix32.exe. Kix32.exe sees all functions when starting the script so it doe snot really matter where the UDF is placed. I usually put it into a separate file and use this to incorporate it into my script: Code:
call @scriptdir + "\someudf().udf"
The commented line are part of the UDF explaining what the UDF does and how to use it. You could leave it out but I always keep it in so some other admin can see what it does and how to use it.
Check out this post on how to use UDF's. There are lots of UDF's available here. Just have a look here.
Edited by Mart (2005-08-17 09:00 PM)
|
|
Top
|
|
|
|
#145748 - 2005-08-17 09:46 PM
Re: Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
pardon my ignorance, but i feel like i'm sooooo close to getting this to work. i'm not sure at all what i'm supposed to be filling in for sections like this: Function EnumProcess($exe, optional $terminate, optional $Computer). in general, i'm not sure what parts are variables in the entire function that i need to do something with. i tried copying exactly as it was from above and got all kinds of errors. so much so, that the script wouldn't run anything before the function! it just killed the whole script entirely. thanks again for your help.
|
|
Top
|
|
|
|
#145750 - 2005-08-17 10:31 PM
Re: Move My Documents via writevalue
|
Mart
KiX Supporter
   
Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
|
Ok. This works. I tested it on my machine and no errors. Took a while cause I accidentally fubared my machine and had to reboot  It assumes that the R drive is already mapped. Keys taken from MS document: http://www.microsoft.com/windowsxp/using/networking/learnmore/honeycutt.mspx
Code:
$Key = "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" $Redirected = ReadValue ($Key, "My Docs and My Pics redirected")
Select Case $Redirected <> "Yes" MD "R:\My Documents\My Pictures" ?"Error: " @ERROR @SERROR WriteValue ($Key, "Personal", "R:\My Documents", "REG_EXPAND_SZ") ?"Error: " @ERROR @SERROR WriteValue ($Key, "My Pictures", "R:\My Documents\My Pictures", "REG_EXPAND_SZ") ?"Error: " @ERROR @SERROR WriteValue ($Key, "My Docs and My Pics redirected", "Yes", "REG_SZ") ?"Error: " @ERROR @SERROR $kill= EnumProcess("explorer.exe",1)
Case 1 ?"No changes needed." EndSelect
;DO NOT change anything below this line!! This UDF is ready for use as it is. Function EnumProcess($exe, optional $terminate, optional $Computer) Dim $winmgmts, $ExecQuery, $Process, $id If NOT $computer $computer=@wksta EndIf $winmgmts="winmgmts:{impersonationLevel=impersonate}!//$COMPUTER" Select Case Val($exe)>0 $ExecQuery="select * from Win32_Process where ProcessId='$exe'" $GetObject=GetObject($winmgmts).ExecQuery($ExecQuery) For Each $Process in $GetObject If $terminate $=$Process.Terminate EndIf $EnumProcess = $Process.name Next $GetObject='' Case VarType($exe)=8 $ExecQuery="select * from Win32_Process where Name='$exe'" $GetObject=GetObject($winmgmts).ExecQuery($ExecQuery) For Each $Process in $GetObject If $terminate $=$Process.Terminate EndIf $id=$Process.ProcessId $EnumProcess = "$Id" + "|" + "$EnumProcess" Next $EnumProcess=Left($EnumProcess,Len($EnumProcess)-1) $GetObject='' Case 1 Exit 1 EndSelect EndFunction
If you have any error please post your windows version and SP and the kix version you are using.
Edited by Mart (2005-08-17 10:33 PM)
_________________________
Mart
- Chuck Norris once sold ebay to ebay on ebay.
|
|
Top
|
|
|
|
#145751 - 2005-08-17 10:51 PM
Re: Move My Documents via writevalue
|
endodave
Starting to like KiXtart
Registered: 2005-08-17
Posts: 101
|
there are a couple of questions now:
1. i changed the mapping to my docs on the desktop and the value was rewritten in to the reg. however, when i logged out and back in, it said no changes were necessary and therefore, did not change the docs back to R:\. what is it reading to determine whether or not a change is needed?
2. what does the md command do? make directory?
3. i pulled out this section: $rc = ReadValue ("subkey", "entry")If $rc <> "R:\" WriteValue ("subkey", "entry", "expression", "data type") $kill= EnumProcess("explorer.exe",1)Else ?"No changes needed skipping to end."EndIf.
does it need to be left in?
thanks dude, you rock!
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1662 anonymous users online.
|
|
|