InterviewSolution
| 1. |
Solve : Batch - Using IF/Else statement with system info? |
|
Answer» Here is the code that i have so far alrighty, i have another question but this time i am really stumped Are you running the batch file as administrator? It should be necessary already if you're accessing system32, but I wanted to make sure. Another suggestion (see around where I put the REM commands/comments): Code: [Select]c: cd c:\sccm_temp\sap echo "Copying Saplogon File" xcopy "c:\sccm_temp\sap\saplogon.ini" "%appdata%\SAP\Common\" /Y echo "Setting up NWBC client" REM this will save a backup of services to services.bak and the new version to 'services' REM previous code would save two copies of the modified file and no backup copy c:\windows\system32\drivers\etc\services c:\windows\system32\drivers\etc\services.bak type c:\windows\system32\drivers\etc\services.bak | findstr /v sapmsEDV | findstr /v sapmsEPR | findstr /v sapmsEQA > c:\windows\system32\drivers\etc\services echo sapmsEDV 3600/tcp >> c:\windows\system32\drivers\etc\services echo sapmsEPR 3600/tcp >> c:\windows\system32\drivers\etc\services echo sapmsEQA 3600/tcp >> c:\windows\system32\drivers\etc\services regedit /s c:\sccm_temp\sap\DEV_SETTINGS_NWBC.reg <-----------Line 16 If %PROCESSOR_ARCHITECTURE%==AMD64 ( regedit /s c:\sccm_temp\sap\NWBC_Sec_64bit.reg ) else ( regedit /s c:\sccm_temp\sap\NWBC_Sec.reg ) Quote from: TechnoGeek on November 27, 2012, 05:32:28 PM Are you running the batch file as administrator? It should be necessary already if you're accessing system32, but I wanted to make sure. Your REM/Comment code is a nice touch, but why are you looking at the .bak to overwrite the original without the EDV/EPR/EQA? No the batch file is ran as a local user (granted all users have admin rights) so it baffles me that the reg file wont run IN the batch. I have tried nesting the other reg files in the DEV_SETTINGS_NWBC and vice versa; both resulting in the reg file RUNNING but the DEV_SETTINGS_NWBC info never gets DUMPED into the registry. Not sure if it has to do with that its adding things to "HKEY_CURRENT_USER" or that the batch suppresses something that it shouldn't. Quote from: The_Valkyrie on November 28, 2012, 08:49:05 AM Your REM/Comment code is a nice touch, but why are you looking at the .bak to overwrite the original without the EDV/EPR/EQA?If you read your original code carefully, you save two copies of the same file, both with those particular entries removed. The one I wrote *should* save the original, unmodified file as services.bak. The reason I copy from services.bak (original file) to services is to avoid any file-in-use errors from copying services (with lines removed) to itself. Quote No the batch file is ran as a local user (granted all users have admin rights) so it baffles me that the reg file wont run IN the batch. Try this: edit the registry to match what you want it to become, then export those keys. See if there are any differences between the generated .reg file and yours (which could have an error somewhere).Quote from: TechnoGeek on November 28, 2012, 10:41:30 AM If you read your original code carefully, you save two copies of the same file, both with those particular entries removed. The one I wrote *should* save the original, unmodified file as services.bak. The reason I copy from services.bak (original file) to services is to avoid any file-in-use errors from copying services (with lines removed) to itself.Oh I see! Quote from: TechnoGeek on November 28, 2012, 10:41:30 AM Try this: edit the registry to match what you want it to become, then export those keys. See if there are any differences between the generated .reg file and yours (which could have an error somewhere). Tried that, the export and the .reg file are the same down to the ordering of entries. I am super baffled so i found a fix, kinda weird but its a start: create another batch with the following Code: [Select]reg add "HKCU\Software\SAP\NWBC\Settings\Pages\RuntimeConnections\BAG" /v "URL" /t "REG_SZ" /d "http://" Then use the original batch above to call this batch and BAM! you have yourselves an EDITED registry in the HKCU area. Now i MUST make it all in one cause im lazy and RATHER push 1 file than 4 files. Quote IF %systemtype%==AMD64 iI believe you need quotes sine you're matching a variable to a string Try:Code: [Select]IF '%systemtype%'=='AMD64' dont know if thats still a problem, but that should fix it. im no expert, but have had the same problem before with batch files. Quote from: TechnoGeek on November 28, 2012, 10:41:30 AM If you read your original code carefully, you save two copies of the same file, both with those particular entries removed. The one I wrote *should* save the original, unmodified file as services.bak. The reason I copy from services.bak (original file) to services is to avoid any file-in-use errors from copying services (with lines removed) to itself. found an issue with your code: Code: [Select]copy c:\windows\system32\drivers\etc\services c:\windows\system32\drivers\etc\services.bak type c:\windows\system32\drivers\etc\services.bak | findstr /v sapmsEDV | findstr /v sapmsEPR | findstr /v sapmsEQA > c:\windows\system32\drivers\etc\servicesThe first line returns an "access denied" when running it. Yes, the line works when its ran as admin but i cant specify to run as admin in SCCM's task sequence. I CAN, however, issue commands that can start this batch as admin or execute the batch that contains admin escalation....just dont know how to do that right now. Warning: this topic has not been posted in for at least 30 days. Unless you're sure you want to reply, please consider starting a new topic. ^I'm use to using 1 thread as to be respectful and tidy^ anyways!!!!! Anyone of you Ladies and Gentleman know the best way to write data to the C:\windows\systems32\drivers\etc\services file without being phycially near the computer (ie. remote) Currently I have this batch (see parts above) that needs to write to the services file. Well that needs to be ran as admin.....can't log onto all 857 computers to do this so i rather make a script. KICKER: the admin password is the same but with different variations (ie. password, Password, PassWord, passw0rd, etc) thank you |
|