I have recently gotten a script together for querying the reg for a temp folder path and cleaning the folder and it works great(Thanks Compo) but when used remotely with psexec it says, "The system was unable to find the specified registry key or value." Before I use PSEXEC to execute the batch I first have it copied to the C:\ and I use this to do that.
set /p cpu=
robocopy "\\nmcfs01\software\scripts\Jacob's Awesome Outlook Scripts" \\%cpu%\c$\Jacob'sTemp
That part goes well then I execute it with psexec with
psexec \\%cpu% -u administrator -i -d "C:\Jacob'sTemp\compo.bat"
That connects but when it executes the batch file it does not find the reg key. HOWEVER, if I go to the C:\Jacob'sTemp and double click on the compo.bat file it works fine and deletes out the files. Also, if I just use PSEXEC to execute it again outside of this script just separately after it is copied over it still does not work. Here is the script I am using for cleaning it up.
#Echo Off
SetLocal EnableExtensions
(Set OV=14.0)
Choice /C YN /M "Delete Outlook Temp Files?"
If ErrorLevel 2 Exit/B
Set "BK=HKCU\SOFTWARE\Microsoft\Office\"
Set "EK=\Outlook\Security"
Set "VN=OutlookSecureTempFolder"
For /F "Tokens=2*" %%I In ('Reg Query "%BK%%OV%%EK%" /V %VN%') Do Set "VD=%%J"
PushD "%VD%" && (RD/S/Q "%VD%" 2>Nul) && PopD
pause
REM The below commands will empty Jacob'sTemp:
If Exist "%SystemDrive%\Jacob'sTemp" (PushD "%SystemDrive%\Jacob'sTemp" && (
(RD/S/Q "%SystemDrive%\Jacob'sTemp" 2>Nul) && PopD
pause
REM The below commands without the first two characters will remove Jacob'sTemp
If Exist "%SystemDrive%\Jacob'sTemp" (RD/S/Q "%SystemDrive%\Jacob'sTemp"
Pause
Echo(------------------------------------------------------------------------------
Echo( Complete! Goodbye!
Echo(------------------------------------------------------------------------------
Timeout 5 >Nul
It would be a huge help to have this work as intended where we can just type the computer name in and done but I do not know why it does not work when executed remotely and it is copied to the computer. Any help is much appreciated!
HKCU, the target of your reg query, is a per user registry hive. psexec's remote service runs in SYSTEM account and when it issues reg query that wont be directed to the remote machine's currently logged-in user's HKCU. It would be directed to the SYSTEM account's HKCU which maps under HKEY_USERS\S-1-5-18\Software.... Hence the error "The system was unable to find the specified registry key or value."
Related
I have a NSIS script with RequestExecutionLevel admin set and within this I invoke a .bat script which adds a reg key.
When the batch-file is executed through command-prompt the reg key gets added. But when running the installer, it executes the .bat file but fails to add the reg key.
nsExec::ExecToStack '"$pluginsdir${SETUP_PATH}\UpdateNtpConfiguration.bat" $Ip1'
UpdateNtpConfiguration.bat content
set adds=%1
REM Get the list of ntp servers showing up in System Date & Time->Internet Time dropdown
set "num=0"
for /F %%G in ('reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers ^| findstr "^[^a-z] ^("') do if %%G GTR !num! set "num=%%G"
set /A num=num + 1
REM Add address at the end
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers /v "%num%" /t REG_SZ /d "%adds%" /f
goto:eof
Just like #Anders said, there are built in functions for that.
https://nsis.sourceforge.io/Docs/Chapter4.html#registry
If an an error happens with this command, it will be a lot easier to debug as it is built-in.
If you're not doing anything else in the batch file, it is better to find out if NSIS has a command already integrated with it....
EDIT:
It also might be that the admin installer is run the bat file without admin privs.
After some debugging found out that NSIS was writing the registry values in 32 bit reg space(HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft). I had to append /reg:64 to make it add to the 64 bit reg space.
Also the reason I had the bat script was to have some logic to look for duplicates before adding the key.
My goal is to create a batch script to copy a folder with subfolders to user desktop with overwrite option and minimized of command prompt.
I am pushing the script through Group policy in user start up screen.
However I am getting an error when running the script locally. Not sure what I am missing in the script..
#echo off
#cls
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized
echo Your Source Path:
set INPUT1=\\X.X.X.X\Test\TMS\
echo Your Destination Path:
set INPUT2=C:\Users\%Username%\Desktop\
xcopy %INPUT1% %INPUT2% /y /s
:minimized
You mentioned folder, so I am writing this assuming you want to create the TMS folder with content on the desktop.
I would try something like this inside of you minimized label. This is untested as I have no Network drives to test with.
for /f "tokens=2" %i in ('net use * "\\X.X.X.X\Test\TMS\" ^| findstr /i Drive') do set "tmpDr=%%i"
mkdir "%USERPROFILE%\Desktop\TMS" >nul
xcopy "%tmpDir%\*" "%USERPROFILE%\Desktop\TMS" /s /y
net use /d %tmpDir% >nul
Some things to note in your code. You have 2 minimized labels, you need to enclose path variables with double quotes to eliminate possible whitespace, you can drop the echo's seeing as you plan on running the script minimized. Last but not least, you do not need to specify full path to the user's desktop as %USERPROFILE% variable already exists as Drive:\Users\Username
I've been working very hard on a now, very very long script. What I need to do is find the installation directory for a given piece of software. I was using
for /f "tokens=2*" %%a in ('REG Query "HKEY_CLASSES_ROOT\TypeLib\{1779292D-1DAD-47E3-9404-8B32455264C2}\8.1e\HELPDIR" /ve 2^>nul') do set "ExeLoc=%%~b"
The problem with this is that it only works on the latest version of the software. Is there a way I can check the Programs and Features for an application, then grab the directory and set it to "ExeLoc"? And is there a way to do this without being too specific? For example, let's say "Program" is the application name, but in Programs and Features it may show up as "Program" or "Program Client" or "Program Version X.Y" or "Program Client Version X.Y". Would there be a way to search for "Starts with Program" then grab the path from there?
Let me know if you need further information from me.
Oh, and this needs to be within a batch file, without installing any additional API or other scripts, because it needs to be able to run on any machine on the fly, and we're not allowed to install additional software on machines.
Here is the help of the command Where
Try this batch that can accept wildcards with the command Where.exe as string input :
#echo off
Mode con cols=90 lines=15
set Location=C:\Program files
Set FileName=Program*
Set Tmp=Tmp.txt
Set SearchResult=SearchResult.txt
echo( & cls
echo( & echo Please Wait for moment .... Searching for "%FileName%" on "%Location%"
where /r "%Location%" "%FileName%" > %Tmp%
Cmd /U /C Type %Tmp% > %SearchResult%
Del %Tmp%
Start %SearchResult%
I have a simple batch script that copies files locally from a Sharepoint drive that's mapped on the local machine. This runs just fine when being manually run, but when run using task scheduler, it seems as though the script cannot access the drive at all. Even a simple DIR print out fails. It's also worth noting that the user set to run the script in scheduler has full rights to everything involved and is the same account being used to run it manually.
A couple of the settings for the scheduled task:
set to run whether user is logged in or not
running with highest privileges
Any idea how I could get this working in scheduler?
Edit:
Screen shots of the scripts and the task run history
http://imgur.com/a/wCsET
EDIT 2
callCopyFiles.bat
del "C:\apache\htdocs\IESite\Reports\*.*?"
FOR /f "delims=" %%L in (directorylist.txt) do (
echo %%L >> log.txt
CALL copyfiles.bat "%%L"
)
copyfiles.bat
FOR /F "delims=" %%I IN ('DIR %1 /s /b /O:-D') DO (
COPY "%%I" "C:\apache\htdocs\IESite\Reports"
goto :end
)
:ender
My suspicion is that this line in callCopyFiles.bat:
CALL copyfiles.bat "%%L"
is failing because the current directory is different when your batch file is running as a scheduled task.
Try changing this line to list the full path...something like:
CALL C:\YourFolderHere\copyfiles.bat "%%L"
EDIT
Based on the comments, I think you likely need to map the Z: drive within the copyfiles.bat file.
EDIT 2
Don't specify the credentials when mapping the drive.
Just add NET USE Z: \\YourServer\ShareName to the copyfiles.bat file.
I am trying to remove Dropbox from around 500+ Windows 7 computers using a batch script. Dropbox is installed on a per-user basis under "%APPDATA%\Dropbox".
To uninstall silently you have to run "%APPDATA%\Dropbox\bin\DropboxUninstaller.exe /S". I have tested this command and it works fine, but the problem is it only uninstalls it from the user directory you run it from. I have tried taking the DropboxUninstaller.exe file and running it from the root of C:, but it fails.
I will be pushing this script out via SCCM, so it will run under the SYSTEM account. I need to find a way to loop between all of the user direcories, find which profiles have the Dropbox\bin\DropboxUninstaller.exe path/file and run it in that location.
I have tested logging in as another user (local admin) and running the Dropbox uninstaller from another users directory, and it uninstalls fine for the user whos directory I run it in, so I know this will work.
If anyone could help me out with the correct command, that would be great! I have googled around for an answer, but it doesn't seem to be out there.
Thanks in advance,
Search user profiles, and for each if unistaller exists, execute it (asumming an "standard" installation, maybe this needs to be adjusted)
#echo off
setlocal enableextensions
for /F "tokens=2,*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v ProfileImagePath /s ^| find "REG_EXPAND_SZ" ^| findstr /v /i "\\windows\\ \\system32\\"') do (
call :doUninstall "%%b"
)
endlocal
exit /b
:doUninstall
set "_uninstaller=%~1\AppData\Roaming\Dropbox\bin\DropboxUninstaller.exe"
if not exist "%_uninstaller%" goto :EOF
start "" /wait "%_uninstaller%" /S
goto :EOF
for /r c:\windows %A in (notepad.exe) do "%A" %windir%\win.ini
Remember %%A in a batch and %A at command prompt.