Page 1 of 1 1
Topic Options
#185449 - 2008-02-18 10:43 PM Login Scripts copy function
duo Offline
Getting the hang of it

Registered: 2007-10-25
Posts: 61
Loc: iowa
I am looking to replace
 Code:
function copy_files($personal,$desktop,$start,$server,$program)
DIM $file
$file=$server + "icons$\" + $program
	if not exist ("$personal")
		md "S:\icons\"
	endif
	if not exist ("$personal$program")
		;? "need in personal drive"
		COPY "$file" "$personal" /c
		error_check(@ERROR,@SERROR,"couldnt copy $file to $personal")
	endif
	if not exist ("$desktop$program")
		;? "need in desktop"
		COPY "$file" "$desktop" /c
		error_check(@ERROR,@SERROR,"couldnt copy $file to $desktop")
	endif
	if not exist ("$start")
		md "C:\documents and settings\"+@USERID+"\start menu\programs\apps\"
	endif
	if not exist ("$start$program")
		;? "need in startmenu"
		COPY "$file" "$start" /c
		error_check(@ERROR,@SERROR,"couldnt copy $file to $start")

	endif
endfunction


With

 Code:
function copy_files($personal,$desktop,$start,$server,$program)
DIM $comp_return,$icons_path,$file
$icons_path='icons$\'
$file=$server + $icons_path + $program

	if not exist ($personal)
		md $personal	;make sure personal location exists
	endif
	if not exist ($start)
		md $start	;make sure start location exists
	endif

	$comp_return=CompareFileTimes('$server+$icons_path+$program','$personal+program$')
		if $comp_return <> 0
			;? "need in personal drive"
			COPY "$file" "$personal" /c
			error_check(@ERROR,@SERROR,"couldnt copy $file to $personal")
		endif

	$comp_return=CompareFileTimes('$server+$icons_path+$program','$desktop+program$')
		if $comp_return <> 0
			;? "need in desktop"
			COPY "$file" "$desktop" /c
			error_check(@ERROR,@SERROR,"couldnt copy $file to $desktop")
		endif

	$comp_return=CompareFileTimes('$server+$icons_path+$program','$start+program$')
		if $comp_return <> 0
			;? "need in startmenu"
			COPY "$file" "$start" /c
			error_check(@ERROR,@SERROR,"couldnt copy $file to $start")
		endif
endfunction

Here are my current params
 Code:
if $osname="Windows Vi"
	;Vista Paths
	$vista=1
	$personal_loc="S:\icons\"
	$desktop_loc="C:\Users\"+@USERID+"\Desktop\"
	$start_loc="C:\Users\"+@USERID+"\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\apps\"
else
	;XP,2k,2k3 Paths
	$personal_loc="S:\icons\"
	$desktop_loc="C:\documents and settings\"+@USERID+"\desktop\"
	$start_loc="C:\documents and settings\"+@USERID+"\start menu\programs\apps\"
endif


Any warnings from someone who's done something simalar?


Edited by duo (2008-02-18 10:54 PM)
Edit Reason: fixed code to where no errors are generated

Top
#185450 - 2008-02-18 11:03 PM Re: Login Scripts copy function [Re: duo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Any reason you won't use the recommended "%USERPROFILE%" ??? Using @USERID to build a profile or user home path is unreliable. The point of @USERID is to identify the Account Name of the person logged in, and does not necessarily have anything to do with user paths.

My home path on Vista is "C:\Users\glenn.DOMAIN", since I also have a local profile of "C:\Users\Glenn". Clearly, if I ran your script in my environment, I'd be getting errors trying to update a folder that I did not have permissions to, even though it was "mine".

%USERPROFILE% will contain the correct value regardless of the O/S you are running, and will reflect the correct domain or local profile path.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185451 - 2008-02-18 11:11 PM Re: Login Scripts copy function [Re: Glenn Barnas]
duo Offline
Getting the hang of it

Registered: 2007-10-25
Posts: 61
Loc: iowa
so like
$desktop_loc='%USERPROFILE%\Desktop'
$start_loc='%USERPROFILE%\Start Menu';XP
$start_loc='%APPDATA%\Microsoft\Windows\Start Menu\Programs\apps\';vitha


This what your getting at?

Top
#185457 - 2008-02-19 02:26 AM Re: Login Scripts copy function [Re: duo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
 Code:
$Desktop_Loc = '%USERPROFILE%\Desktop'
$Start_Loc = IIf("%APPDATA% = '', '%USERPROFILE%\Start Menu', '%USERPROFILE%\appdata')

My AppData folder has Local, LocalLow, and Roaming subfolders, with a Microsoft folder only under Local. I DO NOT have a roaming profile, yet my AppData variable points to "C:\Users\Glenn.DOMAIN\AppData\Roaming". The point is - APPDATA doesn't appear to be that valuable by itself. My code example tests the APPDATA value, which isn't set on XP. If it's null, it sets the StartLoc var accordingly to the BASE folder. You'll need further tests to determine how to dig into the start folder from there, depending on what you want to do and what O/S you have.

BTW - I'm running Vista Ultimate x64, so I checked the other two workstations here and found the same "roaming" folder on the tail, including the one PC that's got Vista X86 Home still on it.

Again, the environment vars will generally be a better representation of the base location on the computer you're connected to.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185471 - 2008-02-19 08:27 AM Re: Login Scripts copy function [Re: duo]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Desktop is in the registry
Key=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
Name=Desktop

Start Menu is also in the registry
Key=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
Name=Start Menu

 Code:
Break On
Dim $ShellFolders, $Desktop, $StartMenu
$ShellFolders="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
$Desktop   = ReadValue($ShellFolders,"Desktop")
$StartMenu = ReadValue($ShellFolders,"Start Menu")
? $Desktop
? $StartMenu

Top
#185476 - 2008-02-19 04:00 PM Re: Login Scripts copy function [Re: Witto]
duo Offline
Getting the hang of it

Registered: 2007-10-25
Posts: 61
Loc: iowa
I dont like going the registry route, because once i go down that path, im going to want to add ridiculous things, mapping my documents to S:\My Documents. auto syncing and that sort of jazz
Top
#185478 - 2008-02-19 04:16 PM Re: Login Scripts copy function [Re: duo]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
I'd go
 Code:
$desktop_loc=EXPANDENVIRONMENTVARS('%USERPROFILE%')+'\Desktop'
$start_loc=EXPANDENVIRONMENTVARS('%USERPROFILE%')+'\Start Menu'
$start_loc='EXPANDENVIRONMENTVARS('%APPDATA%')+'\Microsoft\Windows\Start Menu\Programs\apps\'
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#185479 - 2008-02-19 04:21 PM Re: Login Scripts copy function [Re: duo]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Your choice. I just suggested a (IMHO) good way to get the path of the folders you are looking for.
Maybe you can do it this way:
GetSpecialFolders() - Returns the Name and Path of Special Folders
 Code:
Break On
Dim $objFolderItem
;Desktop
$objFolderItem=createobject('Shell.Application').Namespace(16).Self
? $objFolderItem.Name
? $objFolderItem.Path
;Start Menu
$objFolderItem=createobject('Shell.Application').Namespace(11).Self
? $objFolderItem.Name
? $objFolderItem.Path
$objFolderItem=0

Top
#185481 - 2008-02-19 04:33 PM Re: Login Scripts copy function [Re: Glenn Barnas]
duo Offline
Getting the hang of it

Registered: 2007-10-25
Posts: 61
Loc: iowa
 Originally Posted By: Glenn Barnas

My AppData folder has Local, LocalLow, and Roaming subfolders, with a Microsoft folder only under Local. I DO NOT have a roaming profile, yet my AppData variable points to "C:\Users\Glenn.DOMAIN\AppData\Roaming". The point is - APPDATA doesn't appear to be that valuable by itself. My code example tests the APPDATA value, which isn't set on XP. If it's null, it sets the StartLoc var accordingly to the BASE folder. You'll need further tests to determine how to dig into the start folder from there, depending on what you want to do and what O/S you have.

BTW - I'm running Vista Ultimate x64, so I checked the other two workstations here and found the same "roaming" folder on the tail, including the one PC that's got Vista X86 Home still on it.

Again, the environment vars will generally be a better representation of the base location on the computer you're connected to.

Glenn

Where is the default supposed to be? I had a hard crash one time and when it rebooted all my files/settings were gone. I assume it screwed up the profile at that point.

Top
#185482 - 2008-02-19 04:53 PM Re: Login Scripts copy function [Re: Björn]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
Björn:

Why are you using the ExpandEnvironmentVars() function? That's extra overhead in this situation, as environment vars are expanded automatically in normal strings.

When you really need to use it is when you are reading Registry or INI strings that might have embedded environment vars.

Just a minor ripe nit to pick. ;\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185483 - 2008-02-19 04:58 PM Re: Login Scripts copy function [Re: duo]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4403
Loc: New Jersey
The registry is also a very accurate and direct way to go. I wanted to illustrate that using @USERID would cause problems, so expanded upon the Environment Var discussion.

I'm not sure about the default config. I'm still trying to find enough time to resolve the minor programming issues between Vista and everything else. \:\( Again, wanted to point out that your coded path was not universal - might work often, but then will do strange things on a few systems.. causing you to lose hair (and look like me - hence the need for the hat in my avatar).

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#185484 - 2008-02-19 05:54 PM Re: Login Scripts copy function [Re: Glenn Barnas]
duo Offline
Getting the hang of it

Registered: 2007-10-25
Posts: 61
Loc: iowa
hair...hell im 23 and losing it rapidly as is(had a massive head injury at 18 that started the trigger)
Top
#185503 - 2008-02-20 11:11 AM Re: Login Scripts copy function [Re: Glenn Barnas]
Björn Offline
Korg Regular
*****

Registered: 2005-12-07
Posts: 953
Loc: Stockholm, Sweden.
Oh, yes so they are true enough. So, acctually I don't know why I added that, just felt right ;). But string-seperation should at least be kept.
_________________________
as long as it works - why fix it?
If it doesn't work - kix-it!

Top
#185509 - 2008-02-20 03:41 PM Re: Login Scripts copy function [Re: Björn]
duo Offline
Getting the hang of it

Registered: 2007-10-25
Posts: 61
Loc: iowa
Alright how about this, whats the best way to alter the shell paths? Change My documents to per say S:\My Documents, etc. Looking for the most proper way, and i would like to encorporate the best method for setting $start_loc and such

Edited by duo (2008-02-20 04:07 PM)

Top
#185512 - 2008-02-20 04:28 PM Re: Login Scripts copy function [Re: duo]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
The absolute best way is top use a GPO.
If you have to do this with a script then reading the current paths from the registry and writing the new path to the registry would be the way to go.

I guess you already know but just in case you don’t. Be aware that a lot of changes to the registry are not instant and require a reboot.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#185513 - 2008-02-20 04:46 PM Re: Login Scripts copy function [Re: Mart]
duo Offline
Getting the hang of it

Registered: 2007-10-25
Posts: 61
Loc: iowa
GPOs are not my neighbor...
Top
Page 1 of 1 1


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

Who's Online
0 registered and 857 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.108 seconds in which 0.064 seconds were spent on a total of 13 queries. Zlib compression enabled.

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