Page 1 of 1 1
Topic Options
#124783 - 2004-08-12 10:57 AM How to specify "User Name" parameter in a Delete command ?
westham Offline
Fresh Scripter

Registered: 2003-05-28
Posts: 16
I need to delete the normal.dot file from C:\Documents and Settings\username.domain\Application Data\Microsoft\Templates folder where username is my Windows 2000 AD user account and domain is my Windows 2000 domain. Anyone has any idea how this can be done via kix logon script ?

I know I can use $user=@userid to get the Windows 2000 AD user account. But it seems that I can't incorporate this into the delete command to delete the normal.dot file.

Cheers

Top
#124784 - 2004-08-12 11:07 AM Re: How to specify "User Name" parameter in a Delete command ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Check the %USERPROFILE% environment variable - it should get you a bit closer.

Post the code that is failing for you. The most common cause of problems is spaces and other special characters in the path.

Top
#124785 - 2004-08-12 12:03 PM Re: How to specify "User Name" parameter in a Delete command ?
westham Offline
Fresh Scripter

Registered: 2003-05-28
Posts: 16
$user=@userid

del C:\Documents and Settings\"$user".DOMAIN\Application Data\Microsoft\Templates\normal.dot where DOMAIN is the domain name

OR

del C:\Documents and Settings\$user.DOMAIN\Application Data\Microsoft\Templates\normal.dot where DOMAIN is the domain name

This may looks silly... was just trying my luck...

Top
#124786 - 2004-08-12 12:12 PM Re: How to specify "User Name" parameter in a Delete command ?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
del "C:\Documents and Settings\" + @userid + ".DOMAIN\Application Data\Microsoft\Templates\normal.dot"

this might work better
_________________________



Top
#124787 - 2004-08-12 12:20 PM Re: How to specify "User Name" parameter in a Delete command ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
...but you really shouldn't be hard coding it.

What is your environment variable %USERPROFILE% set to?
Code:
"Profile path is: "+%USERPROFILE% ?


Top
#124788 - 2004-08-12 12:33 PM Re: How to specify "User Name" parameter in a Delete command ?
westham Offline
Fresh Scripter

Registered: 2003-05-28
Posts: 16
this is getting nearer as i did not encountered any error while executing the stm... however, the file was not deleted at all...

tried all the followings but somehow the file just don't get deleted:-

del "C:\Documents and Settings\" + @userid + ".DOMAIN\Application Data\Microsoft\Templates\normal.dot"

del "C:\Documents and Settings\" + "@userid" + ".DOMAIN\Application Data\Microsoft\Templates\normal.dot"

del "C:\Documents and Settings\" + $user + ".DOMAIN\Application Data\Microsoft\Templates\normal.dot"

del "C:\Documents and Settings\" + "$user" + ".DOMAIN\Application Data\Microsoft\Templates\normal.dot"

Top
#124789 - 2004-08-12 12:36 PM Re: How to specify "User Name" parameter in a Delete command ?
westham Offline
Fresh Scripter

Registered: 2003-05-28
Posts: 16
i can't locate this environment variable %USERPROFILE%... do we have that by default ? not too familiar with environment variable thingy... appreciate if u cld elaborate... thanks
Top
#124790 - 2004-08-12 12:54 PM Re: How to specify "User Name" parameter in a Delete command ?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Open a DOS console and type "set" - you should see all your environment variables.

It's present in Win XP, I don't have a 2K box to hand to check.

If the delete fails it will do so silently. To check the status, use the @ERROR macro.

After you delete command, add the following line:
Code:
"Delete status was "+@ERROR+": "+@SERROR+@CRLF



This should give you a "0" status (which is success), or a value which indicates what the error was.

Top
#124791 - 2004-08-12 01:37 PM Re: How to specify "User Name" parameter in a Delete command ?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
excerpt from a 'set' command on W2k :

USERPROFILE=C:\Documents and Settings\Administrator

so this is there by default ...
_________________________



Top
#124792 - 2004-08-12 03:17 PM Re: How to specify "User Name" parameter in a Delete command ?
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
You should NEVER hard code the username in a path like that. Yes, the %USERPROFILE% enviro var works, but you can get that and much more by pulling values from the reg key:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#124793 - 2004-08-13 04:39 AM Re: How to specify "User Name" parameter in a Delete command ?
westham Offline
Fresh Scripter

Registered: 2003-05-28
Posts: 16
del "%USERPROFILE%" + "\Application Data\Microsoft\Templates\normal.dot"

The above works Mine is a Windows XP machine too.

Thanks alot, Richard ! Thanks to all who ve contributed too !

Top
#124794 - 2004-08-13 10:30 AM Re: How to specify "User Name" parameter in a Delete command ?
Anonymous
Unregistered


Then you could also use:

del "%AppData%\Microsoft\Templates\normal.dot"

gr,
DS

Top
#124795 - 2004-08-13 02:18 PM Re: How to specify "User Name" parameter in a Delete command ?
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Or you could do it this way..
Code:

$RegKey='HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
$Templates=READVALUE($RegKey,'Templates')
DEL $Templates+'\Normal.Dot'



HTH,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

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 837 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.035 seconds in which 0.014 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