Computing.Net > Forums > Windows XP > Batch file help (get current user)

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch file help (get current user)

Reply to Message Icon

Name: Joseph
Date: October 23, 2003 at 13:34:12 Pacific
OS: XP Pro
CPU/Ram: P4 @ 1.8, 512MB
Comment:

First, let me give you a background. Here at work, everyone is assigned a user id (i.e. u257949 or u259974). They're always a "u" and 6 digits. That is what their username for windows is set to (i.e. "C:\Documents and Settings\u257949"). What I need to do now is create a batch file to delete a file (named YIPN.BAT) from the user's Startup folder (i.e. "C:\Documents and Settings\u257949\Start Menu\Programs\Startup"). Because not everyone has these files, they were not placed in the All Users directory, thus the need to get the current user.

I've done massive google searches and I cannot get it to work. I've tried to do two different methods; 1) asking the user for input and plugging it in to the "username" space and 2) getting the current user from the registry and plugging it in. I can get both methods two work alone, but cannot integrate it in to my "erasing" batch. I must admit that I am a newbie at creating batches, so this may be something simple. I know a lot of DOS commands, but this just blows me away for some reason.

Oh, also, I would just give each user instructions on how to delete the file, but most everyone here is about 75% computer illeterate and it would take forever just to delete the one file. That is why I am trying to create a batch file to do it for me.

I'm at a stand still so if you can help, please do. Thanks!




Sponsored Link
Ads by Google

Response Number 1
Name: Randall Lewis
Date: October 23, 2003 at 14:39:46 Pacific
Reply:

create batch "fclean.bat" file with userinput option and put it somewhere on network or in their c:\

del C:\Documents and Settings\%1\Start Menu\Programs\Startup\yipin.bat

If the file is in their c:\, The user goes to start, then run
enter the following:
fclean u123456(return)

It should substitute their user number for the %1 in the batch file.

If you have a typical mapped drive, put it there. If it's drive X: then the user would put the following at the run prompt:

X:\fclean u123456


0

Response Number 2
Name: CyberSlug
Date: October 23, 2003 at 14:43:37 Pacific
Reply:

Sound like a job for AutoIt (getAutoItv3Setup.exe).

; You can compile this sample script into an EXE
;
$usr = RegRead("HKEY_...", "Foo...")

FileDelete("C:\Documents and Settings\" & $usr & "\Start Menu\Programs\Startup\YIPN.BAT")

MsgBox(0,"FYI", "Operation completed!")


0

Response Number 3
Name: Joseph
Date: October 23, 2003 at 18:35:19 Pacific
Reply:

Wow, thanks Randall Lewis. Worked like a charm with a little bit of editing. Instead of being:
"del C:\Documents and Settings\%1\Start Menu\Programs\Startup\yipin.bat"

It should be:
"del C:\Docume~1\%1\StartM~1\Programs\Startup\YIPN.bat"

But just that simple fix was all I needed. Thanks again! (P.S. CyberSlug, I couldn't figure out how to use AutoIt. Any documentation anywhere?)


0

Response Number 4
Name: CyberSlug
Date: October 23, 2003 at 19:19:14 Pacific
Reply:

Glad you got it to work!
(AutoIt should come with a help file in its directory, or you can download it here.)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Batch file help (get current user)

How to push a batch file out to domain users www.computing.net/answers/windows-xp/how-to-push-a-batch-file-out-to-domain-users/178481.html

Batch file help needed... www.computing.net/answers/windows-xp/batch-file-help-needed/163063.html

Batch File Help www.computing.net/answers/windows-xp/batch-file-help/164222.html