1.

Solve : bat problem..think %username% isn't getting complete name...?

Answer»

My apologies if this subject has been covered. I have tried USING the search, as well as drilling through many of the forum pages, but I just haven't seen an answer to what I need. I am not very experienced in DOS and batch files

situation: we have an .EXE file that is downloaded to a user's desktop. When run, the exe extracts a local version of a website to a specific folder on the c drive as well as a batch file. The batch file, among other things, pushes a pre-made shortcut to the desktop, and then removes the .exe file originally downloaded.

We recently moved to XP machines (from 2000) and i noticed that on SOME machines the batch wasn't working as intended. I made some fixes that fixed the adding of the shortcut to the desktop (I had to change "all users"), but I haven't been able to get the exe to delete from the desktop.

After doing some research, I think the issue occurs for users having more than one profile set up in the documents and settings folder. Some of us can log into multiple domains. So... instead of just one profile, for example, y1234567, i have an additional one named y1234567.000.

Unfortunately, when I use %username% to get DOS (or whatever the command shell is with XP) to return the value, the .000 doesn't appear to be recognized by the machine. I CLEARLY have a profile named y1234567.000 in the folder structure, but echoing the %username% request only displays y1234567... since the exe was run from this .000 profile, the batch obviously can't delete something it can't see.

Does anyone know how to get around this?

I thought I could do some CONCATENATION and force the machine to see the .000. I added this to the batch file:

set zeroes=.000
set secondid=%username%%zeroes%

running this in it's own batch file does indeed return the value y1234567.000 but I am not sure the machine recognizes this as the same value as the second profile on the machine. It doesn't appear to as when I create a delete command such the one below, in conjunction with the code above, it doesn't work:

del c:\"documents and settings"\%secondid%\desktop\execute.exe

I even tried a test telling it the specific profile, but no dice...

del c:\"documents and settings"\y1234567.000\desktop\execute.exe

I am thoroughly confused and frustrated as I feel this is probably an academic problem to knowledgeable persons. I apologize for the length of this post, and thanks in advance to anyone who might be able to help.I might not be much help but as far as I have known for PC's when you log in the .000 is removed and the profile shows as the USERNAME only. If you are logged into the PC and run the script with the %username% it should work.

Would it be possible to see the script without any server names or anything?Not much idea

Just try
del "c:\documents and settings\y1234567.000\desktop\execute.exe"

instead of

del c:\"documents and settings"\y1234567.000\desktop\execute.exethanks for the replies. I must admit I stumped by some of this... particularly when commands I test from the command prompt don't seem to execute from the batch file.

for instance... here is the pertinent code in the batch...

del c:\docume~1\%username%\desktop\site1*.*
@if exist c:\site1 rd /s /q c:\site1
move c:\site1tmp\site1 c:\
move c:\site1tmp\windows\desktop\*.* c:\docume~1\%username%\desktop
cmd /c rd "C:\site1tmp" /S /Q

atm.. I'm trying to fix why the exe that extracts the SITE (named site1.exe) and runs the batch doesn't delete the the site1tmp folder when everything is done...

Even more frustrating is that the command cmd /c rd "C:\site1tmp" /S /Q works when tried from the dos prompt, as well as when it's tried from a seperate batch file that only has that line. In fact, I got the format for that line by searching the forums.

I can only conclude that something in the other lines of code in this section prevent my command from executing..but I don't understand what. I thought commands are executed sequentially in a batch, and therefore by the time we get to the last line everything else is done and nothing can cause a problem. Obviously I'm wrong, lol. any help is appreciated.Could you use the %userprofile% var instead of %username%\

This var will return the path to the currently logged on users profile.



Discussion

No Comment Found