Server 2008 UnExpected CMD Output 11 replies

  • 1
  • 2

Please wait...

Sgt. D. Pilla

Uber Geek

50 XP

23rd October 2007

0 Uploads

3,473 Posts

0 Threads

#1 8 years ago

Afternoon,

I've implemented the following part of a login script at one client, it runs as expected on server 2003/Win XP with no issues...

ECHO Deleting Prefetch Files...(Win XP/Vista/Win 7) erase "%windir%\Prefetch\*.*" /f /s /q /a H R A ECHO. ECHO Deleting User Temp Files...(Win XP) erase "%temp%\*.*" /f /s /q /a H R A erase /f /s /q /a H R A %temp% ECHO. ECHO Deleting System Temp Files...(Win XP/Vista/Win 7) erase "%systemdrive%\temp\*.*" /f /s /q /a H R A erase /f /s /q /a H R A "%systemdrive%\temp" ECHO. ECHO Deleting Internet Explorer Temp Files...(Win XP) erase "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files\*.*" /f /s /q /a H R A erase /f /s /q /a H R A "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files" ECHO. ECHO Deleting Internet Explorer Temp Files...(Vista/Win 7)... erase "%sytemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /f /s /q /a H R A erase /f /s /q /a H R A "%systemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files" ECHO. ECHO Deleting User Temp Files...(Vista/Win 7)... erase "%sytemdrive%\Users\%username%\AppData\Local\Temp\*.*" /f /s /q /a H R A erase /f /s /q /a H R A "%systemdrive%\Users\%username%\AppData\Local\Temp"

However, that same part of the login script, does not run under Server 2008 properly... I get output of the following... Deleting User Temp Files...(Win XP) Could Not Find C:\Windows\H Could Not Find C:\Windows\H

Deleting System Temp Files...(Win XP/Vista/Win 7) Could Not Find C:\Windows\H Could Not Find C:\Windows\H

Deleting Internet Explorer Temp Files...(Win XP) Could Not Find C:\Documents and Settings\administrator\Local Settings\Temporary Internet Files\*.* Could Not Find C:\Windows\H Could Not Find C:\Windows\H Could Not Find C:\Documents and Settings\administrator\Local Settings\Temporary Internet Files\*

Deleting Internet Explorer Temp Files...(Vista/Win 7)... Could Not Find C:\Windows\H Could Not Find C:\Windows\H

Deleting User Temp Files...(Vista/Win 7)... Could Not Find C:\Windows\H Could Not Find C:\Windows\H

I've verified the paths are correct and they are, but for some reason it's running \H as a directory, when the only time H is used is as a hidden attribute.

It runs as expected without applying attributes to the erase command.

Any ideas why applying attributes to erase in Server 2008 results in the above output? Remembering that the paths specified in the script are 100% correct.




Kilobyte

What does the Fox say?

69,060 XP

23rd November 2002

0 Uploads

6,468 Posts

0 Threads

#2 8 years ago

What is the output without the /H switch? Does it then give the same error for "R"?

What is the output from a character that is not an attribute switch ("W" maybe?)? Does it produce a different result?

My first thought is that the syntax may have changed slightly with 2008. I did notice on the Microsoft website, that they do have a semi-colon ":".

[/a [:] H R A]




ConstanceJill

Huh yeah, whatever ^^

38,761 XP

6th December 2006

0 Uploads

3,246 Posts

1 Threads

#3 8 years ago

Hi there ^^

I fear it may delete *only* files that have the hidden, system and read only attributes once you get that command line to work.

Here are a few suggestions :

1.a - first run the "attrib -r -h -s *.* /s" command on those folders, then it will be easier to delete them with the erase or del command

1.b - or, if it works under every OS, you may want to use deltree.com from FreeDOS - could be necessary to copy it on all the machines first, or call it from a network drive... but it deletes both files and folders, whichever the attributes are.

2 - instead of "%systemdrive%\Documents and Settings\%username%" or "%sytemdrive%\Users\%username%" you probably can use "%userprofile%", which should work whichever your System is - well, I suppose so at least : just test it :p




Sgt. D. Pilla

Uber Geek

50 XP

23rd October 2007

0 Uploads

3,473 Posts

0 Threads

#4 8 years ago

Thanks Guys. I did try adding a colon to the attribute tag but it didn't work. I ended up just removing it.

Final login script its massive lol... @ECHO OFF color 47 TITLE ALRM Login Script REM Created by Toby Powditch 2010

ECHO Deleting Prefetch Files...(Win XP/Vista/Win 7) erase "%windir%\Prefetch\*.*" /f /s /q >nul rd "%windir%\Prefetch" /q /s >nul mkdir "%windir%\Prefetch" >nul ECHO. ECHO Deleting User Temp Files...(Win XP) erase "%systemdrive%\Documents and Settings\%username%\Local Settings\Temp\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\Documents and Settings\%username%\Local Settings\Temp" >nul rd "%systemdrive%\Documents and Settings\%username%\Local Settings\Temp" /q /s >nul mkdir "%systemdrive%\Documents and Settings\%username%\Local Settings\Temp" >nul ECHO. ECHO Deleting User Temp Files...(Vista/Win 7)... erase "%sytemdrive%\Users\%username%\AppData\Local\Temp\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\Users\%username%\AppData\Local\Temp" >nul rd "%systemdrive%\Users\%username%\AppData\Local\Temp" /q /s >nul mkdir "%systemdrive%\Users\%username%\AppData\Local\Temp" >nul ECHO. ECHO Deleting Internet Explorer Temp Files...(Win XP) erase "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files" >nul rd "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files" /q /s >nul mkdir "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files" >nul ECHO. ECHO Deleting Internet Explorer Temp Files...(Vista/Win 7)... erase "%sytemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files" >nul rd "%systemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files" /q /s >nul mkdir "%systemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files" >nul ECHO. ECHO Deleting System Temp Files...(Win XP/Vista/Win 7) erase "%systemdrive%\temp\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\temp" >nul rd "%systemdrive%\temp" /q /s >nul mkdir "%systemdrive%\temp" >nul ECHO. ECHO Deleting Windows Temp Files...(Win XP/Vista/Win 7) erase "%windir%\Temp\*.*" /f /s /q >nul erase /f /s /q "%windir%\Temp" >nul rd "%windir%\Temp" /q /s >nul mkdir "%windir%\Temp" >nul

ECHO. ECHO Finding Operating System Version ver | find "XP" > nul if %ERRORLEVEL% == 0 goto verxp if %ERRORLEVEL% == 1 goto skipsys ECHO. :verxp ECHO Computer Operating System Detected As Windows XP ECHO Performing System Restore Point Clean Up... \\ALRMEX\NETLOGON\cleansysrestore.vbs

:skipsys ECHO Skipping System Restore Clean, Operating System Not Supported Or Not Found... ECHO. ECHO Adding %username% To Local Admin Group... net localgroup administrators "ALRMNET\Domain Users" /add

ECHO Synchronizing computer time to server... net time \\ALRMEX /set /yes >nul ECHO Time Synchronized Successfully

ECHO. ECHO Redirecting SS System Service To Management Console... net stop dnanodeservice reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Dtex Systems\SystemSkan EE" /v 10.1.1.2 /t REG_SZ /d 255.255.255.255 /f net start dnanodeservice

ECHO. ECHO Opening Firewall Ports... netsh firewall add portopening TCP 139 "F&P Sharing" >nul ECHO Port 139 (TCP) Open OK netsh firewall add portopening TCP 445 "F&P Sharing" >nul ECHO Port 445 (TCP) Open OK netsh firewall add portopening TCP 135 "RPC" >nul ECHO Port 135 (TCP) Open OK netsh firewall add portopening UDP 135 "F&P Sharing" >nul ECHO Port 135 (UDP) Open OK netsh firewall add portopening UDP 137 "F&P Sharing" >nul ECHO Port 137 (UDP) Open OK netsh firewall add portopening TCP 138 "F&P Sharing" >nul ECHO Port 138 (TCP) Open OK netsh firewall add portopening TCP 21 "FTP" >nul ECHO Port 21 (TCP) Open OK netsh firewall add portopening TCP 1145 "SystemSkan Server" >nul ECHO Port 1145 (TCP) Open OK netsh firewall add portopening TCP 21000 "SystemSkan RC Server" >nul ECHO Port 21000 (TCP) Open OK netsh firewall add portopening TCP 22000 "SystemSkan RC Client" >nul ECHO Port 22000 (TCP) Open OK

ECHO. ECHO Mapping Network Drives... REM Deleting Previous Mapped Drives To Prevent Conflict of Drive Letters... net use G: /delete /y >nul net use J: /delete /y >nul net use U: /delete /y >nul net use F: /delete /y >nul net use Z: /delete /y >nul

REM Mapping Drives... net use Z: "\\alrmserver\Users\%username%" >nul IF %ERRORLEVEL% == 1 goto fail net use G: "\\alrm-ptaug\CommonDB" /yes >nul net use J: "\\alrm-ptaug\word"/yes >nul net use U: "\\alrm-ptaug\Docs" /yes >nul :fail net use G: "\\alrm-ptaug\CommonDB" /yes >nul net use J: "\\alrm-ptaug\word"/yes >nul net use U: "\\alrm-ptaug\Docs" /yes >nul net use Z: /home /yes >nul

ECHO Installing Trend Micro Client\Server Security Agent... \\ALRMEX\OFCSCAN\AutoPcc.exe

color 07 exit




ConstanceJill

Huh yeah, whatever ^^

38,761 XP

6th December 2006

0 Uploads

3,246 Posts

1 Threads

#5 8 years ago

Hello again ^^

Sorry I didn't reply earlier, got quite busy and forgot about this thread ^^'

Well your final version seems to still have a few problems.

For example, the drive mapping part, after trying to map Z: to "\\alrmserver\Users\%username%" . It goes directly to :fail if errorlevel is set at "1". But the first three commands it calls in that :fail part are the same it will call if it doesn't go to :fail due to errorlevel being set at "1"... and anyway it will always perform the commands after :fail since you don't move to another part of the script should errorlevel NOT be set at "1".

Also, you assume the port openings are OK no matter what the result ot your netsh commands are.

Another thing again : you have a part where you detect the OS version, yet you don't take advantage of that for the temp files cleaning up.




Sgt. D. Pilla

Uber Geek

50 XP

23rd October 2007

0 Uploads

3,473 Posts

0 Threads

#6 8 years ago

Hello again ^^

Sorry I didn't reply earlier, got quite busy and forgot about this thread ^^'

Well your final version seems to still have a few problems.

For example, the drive mapping part, after trying to map Z: to "\\alrmserver\Users\%username%" . It goes directly to :fail if errorlevel is set at "1". But the first three commands it calls in that :fail part are the same it will call if it doesn't go to :fail due to errorlevel being set at "1"... and anyway it will always perform the commands after :fail since you don't move to another part of the script should errorlevel NOT be set at "1".

Also, you assume the port openings are OK no matter what the result ot your netsh commands are.

Another thing again : you have a part where you detect the OS version, yet you don't take advantage of that for the temp files cleaning up.

Re: Temp Files/OS Detection...To lazy...and I didn't think of that haha.

Port openings issue I knew about, the ECHO "OK" was purely for esthetics reasons, the users don't care if it failed or not, and I don't monitor it. As long as they see "OK" then they are happy. Firewall is disabled in GPO anyway.

The mapping issue I didn't even pick up on, thanks, I'll fix that tomorrow!

Thanks for the input again! Always appriciated! I'll fix those things tomorrow and get back to you!




Sgt. D. Pilla

Uber Geek

50 XP

23rd October 2007

0 Uploads

3,473 Posts

0 Threads

#7 8 years ago

Back... Some changes made to the login script Constance...

Changes made are in bold.

Added Firewall port opening checking. Username checking to determine Trend Client/Server Security Agent install

@ECHO OFF cls color 47 TITLE ALRM Login Script REM Created by Toby Powditch 2010 ECHO. ECHO Checking Username ECHO If your username is found to be marked as "Skipped" some steps will not process. REM Find's username, if found then skip installing Officescan. Some client workstations can't use Officescan as it crashes them. EG Dianne A###. ECHO Username found as '%username%' | find "diannea" > IF %ERRORLEVEL% == 0 goto skipofc ECHO Username found as '%username%' | find "administrator" IF %ERRORLEVEL% == 0 goto skipofc IF %ERRORLEVEL% == 1 goto instofc :instofc ECHO Installing Trend Micro Client\Server Security Agent... start \\ALRMEX\OFCSCAN\AutoPcc.exe :skipofc ECHO Deleting Prefetch Files...(Win XP/Vista/Win 7) erase "%windir%\Prefetch\*.*" /f /s /q >nul rd "%windir%\Prefetch" /q /s >nul mkdir "%windir%\Prefetch" >nul ECHO. ECHO Deleting User Temp Files...(Win XP) erase "%systemdrive%\Documents and Settings\%username%\Local Settings\Temp\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\Documents and Settings\%username%\Local Settings\Temp" >nul rd "%systemdrive%\Documents and Settings\%username%\Local Settings\Temp" /q /s >nul mkdir "%systemdrive%\Documents and Settings\%username%\Local Settings\Temp" >nul ECHO. ECHO Deleting User Temp Files...(Vista/Win 7)... erase "%sytemdrive%\Users\%username%\AppData\Local\Temp\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\Users\%username%\AppData\Local\Temp" >nul rd "%systemdrive%\Users\%username%\AppData\Local\Temp" /q /s >nul mkdir "%systemdrive%\Users\%username%\AppData\Local\Temp" >nul ECHO. ECHO Deleting Internet Explorer Temp Files...(Win XP) erase "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files" >nul rd "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files" /q /s >nul mkdir "%systemdrive%\Documents and Settings\%username%\Local Settings\Temporary Internet Files" >nul ECHO. ECHO Deleting Internet Explorer Temp Files...(Vista/Win 7)... erase "%sytemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files" >nul rd "%systemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files" /q /s >nul mkdir "%systemdrive%\Users\%username%\AppData\Local\Microsoft\Windows\Temporary Internet Files" >nul ECHO. ECHO Deleting System Temp Files...(Win XP/Vista/Win 7) erase "%systemdrive%\temp\*.*" /f /s /q >nul erase /f /s /q "%systemdrive%\temp" >nul rd "%systemdrive%\temp" /q /s >nul mkdir "%systemdrive%\temp" >nul ECHO. ECHO Deleting Windows Temp Files...(Win XP/Vista/Win 7) erase "%windir%\Temp\*.*" /f /s /q >nul erase /f /s /q "%windir%\Temp" >nul rd "%windir%\Temp" /q /s >nul mkdir "%windir%\Temp" >nul

ECHO. ECHO Finding Operating System Version... ver | find "XP" > nul if %ERRORLEVEL% == 0 goto verxp if %ERRORLEVEL% == 1 goto skipsys ECHO. :verxp ECHO Computer Operating System Detected As Windows XP... ECHO Performing System Restore Point Clean Up... \\ALRMEX\NETLOGON\cleansysrestore.vbs goto nxtstp

:skipsys ECHO Skipping System Restore Clean, Operating System Not Supported Or Not Found...

:nxtstp ECHO. ECHO Adding %username% To Local Admin Group... net localgroup administrators "ALRMNET\Domain Users" /add

ECHO Synchronizing Computer Time To Server... net time \\ALRMEX /set /yes >nul ECHO Time Synchronized Successfully

ECHO. ECHO Redirecting SS System Service To Management Console... net stop dnanodeservice reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Dtex Systems\SystemSkan EE" /v ServerIP /t REG_SZ /d 10.1.1.2 /f net start dnanodeservice

ECHO. ECHO Opening Firewall Ports... netsh firewall add portopening TCP 139 "F&P Sharing" >nul IF %ERRORLEVEL% == 0 goto ok1 IF %ERRORLEVEL% == 1 goto fa1 :ok1 ECHO Port 139 (TCP) Open OK goto nx1 :fa1 ECHO Port 139 (TCP) Could Not Be Opened ECHO Opening Next Port... :nx1 netsh firewall add portopening TCP 445 "F&P Sharing" >nul IF %ERRORLEVEL% == 0 goto ok2 IF %ERRORLEVEL% == 1 goto fa2 :ok2 ECHO Port 445 (TCP) Open OK goto nx2 :fa2 ECHO Port 445 (TCP) Could Not Be Opened ECHO Opening Next Port... :nx2 netsh firewall add portopening TCP 135 "RPC" >nul IF %ERRORLEVEL% == 0 goto ok3 IF %ERRORLEVEL% == 1 goto fa3 :ok3 ECHO Port 135 (TCP) Open OK goto nx3 :fa3 ECHO Port 135 (TCP) Could Not Be Opened ECHO Opening Next Port... :nx3 netsh firewall add portopening UDP 135 "F&P Sharing" >nul IF %ERRORLEVEL% == 0 goto ok4 IF %ERRORLEVEL% == 1 goto fa4 :ok4 ECHO Port 135 (UDP) Open OK goto nx4 :fa4 ECHO Port 135 (UDP) Could Not Be Opened ECHO Opening Next Port... :nx4 netsh firewall add portopening UDP 137 "F&P Sharing" >nul IF %ERRORLEVEL% == 0 goto ok5 IF %ERRORLEVEL% == 1 goto fa5 :ok5 ECHO Port 137 (UDP) Open OK goto nx5 :fa5 ECHO Port 137 (UDP) Could Not Be Opened ECHO Opening Next Port... :nx5 netsh firewall add portopening TCP 138 "F&P Sharing" >nul IF %ERRORLEVEL% == 0 goto ok6 IF %ERRORLEVEL% == 1 goto fa6 :ok6 ECHO Port 138 (TCP) Open OK goto nx6 :fa6 ECHO Port 138 (TCP) Could not Be opened ECHO Opening Next Port... :nx6 netsh firewall add portopening TCP 21 "FTP" >nul IF %ERRORLEVEL% == 0 goto ok7 IF %ERRORLEVEL% == 1 goto fa7 :ok7 ECHO Port 21 (TCP) Open OK goto nx7 :fa7 ECHO Port 21 (TCP) Could Not Be Opened ECHO Opening Next Port... :nx7 netsh firewall add portopening TCP 1145 "SystemSkan Server" >nul IF %ERRORLEVEL% == 0 goto ok8 IF %ERRORLEVEL% == 1 goto fa8 :ok8 ECHO Port 1145 (TCP) Open OK goto nx8 :fa8 ECHO Port 1145 (TCP) Could Not Be Opened ECHO Opening Next Port... :nx8 netsh firewall add portopening TCP 21000 "SystemSkan RC Server" >nul IF %ERRORLEVEL% == 0 goto ok9 IF %ERRORLEVEL% == 1 goto fa9 :ok9 ECHO Port 21000 (TCP) Open OK goto nx9 :fa9 ECHO Port 21000 (TCP) Could Not Be Opened ECHO Opening Next Port... :nx9 netsh firewall add portopening TCP 22000 "SystemSkan RC Client" >nul IF %ERRORLEVEL% == 0 goto ok10 IF %ERRORLEVEL% == 1 goto fa10 :ok10 ECHO Port 22000 (TCP) Open OK goto nx10 :fa10 ECHO Port 22000 (TCP) Could Not Be Openend ECHO Continuing Login Script... :nx10 ECHO. ECHO Mapping Network Drives... REM Deleting Previous Mapped Drives To Prevent Conflict of Drive Letters... net use F: /delete /y >nul net use G: /delete /y >nul net use I: /delete /y >nul net use U: /delete /y >nul

REM Mapping Drives... net use F: "\\alrmserver\Users\%username%" >nul IF %ERRORLEVEL% == 1 goto fail net use G: "\\alrmserver\apps" /yes >nul net use I: "\\alrmserver\Services" /yes >nul goto ext :fail net use F: /home /yes >nul net use G: "\\alrmserver\apps" /yes >nul net use I: "\\alrmserver\Services" /yes >nul

:ext color 07 exit




ConstanceJill

Huh yeah, whatever ^^

38,761 XP

6th December 2006

0 Uploads

3,246 Posts

1 Threads

#8 8 years ago

Hi again :]

I'd add a few improvements to the script, but for this I'd need to know the exact output of the "ver" command under Vista and 7.

Anyway, here are some things you probably can do already : - I'm pretty sure you can disable System Restore via GPO (at my work, they actually enable it and try to prevent us from disabling it). - there also is a registry key to completely disable prefetch

Also, I'm wondering something : is that login script running with administrator rights ? For if it isn't, there are lots of things it probably won't be able to do. And if it is, will the network drives be visible and accessible to users ? Would they not have administrator rights on the servers ?




Junk angel

Huh, sound?

166,880 XP

29th January 2007

0 Uploads

15,678 Posts

0 Threads

#9 8 years ago

ver under vista sp2

C:\Users\junk>ver

Microsoft Windows [Verze 6.0.6002]

If it helps You should be okay if you use wilcards after 6. since the difference between 7 and vis is that 7 is 6.1




ConstanceJill

Huh yeah, whatever ^^

38,761 XP

6th December 2006

0 Uploads

3,246 Posts

1 Threads

#10 8 years ago

Thanks :] I guess "Verze" is "Version" in your language ? ^^'




  • 1
  • 2