"ERROR: Invalid syntax. Default option is not allowed more than '2' time(s)." using SETX - windows

I thought I had this working at one time but recently my command quit working. My research here and abroad is not turning up anything I have not attempted already. Perhaps there is some other variable I am missing that SETX is looking at?
My command:
setx /s servername PATH "%Path%";"c:\program files (x86)\java\jre7\bin";"c:\program files (x86)\java\jre7\bin\client" /m
I have tried the same command against a couple of Win2k8 servers to no avail. This has worked but is now producing the error above. I usually run this within a batch file against a list of several servers to push Java out. (Path to java is not being set unless we manually create the entries when remotely installed.)
The existing path on the server I am attempting to update is this:
%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%systemroot%\System32\WindowsPowerShell\v1.0\;C:\BMC\Patrol3\bin;C:\BMC\common\globalc\bin\Windows-x86;C:\BMC\common\globalc\bin\Windows-x86-64;C:\BMC\Patrol3\BEST1\9.5.00\bgs\bin
I did clean up a couple duplicate path entries. Aside from that I did not find anything unusual to me.
Edit:
Tweaking the command to remove some of the quotation marks does allow it to run but with that, it imports the path of the local system replacing the remote systems path and appends the desired path entries.
The revised command:
setx /s servername PATH "%Path%;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin\client" /m
In hopes of fixing this new problem, I am attempting to run the command with psexec. Doing so brings me back to my original problem, "Default option is not allowed more than '2' time(s)". Depending on how I modify the quotes when using psexec I can get "To many Arguments" or command succeeded, path truncated which ends up being the local path being applied on the remote server once again.
The most promising of my attempts:
psexec \\servername -u domain\user -p p#ssw0rd "c:\windows\system32\setx" "Path "%Path%;c:\program files (x86)\java\jre7\bin;c:\program files (x86)\java\jre7\bin\client" /M"
Using the "-s" option on psexec produces the same error, just less detail.

I was able to update the path value on remote systems by creating a batch file to be executed remotely.
Contents of "setJava7path.cmd"
setx Path "%Path%";"%ProgramFiles(x86)%\java\jre7\bin";"%ProgramFiles(x86)%\java\jre7\bin\client" /m
To execute I utilized psexec which copied the batch file to the remote system and executed the command.
psexec \\systemname -c setJava7path.cmd
It adds / changes a line to my overall deployment script but that is livable.

Related

Batch file - Remote Copy and Execute issue

I have a batch file that part of it copies a folder and its content to a local directory and then continues through the batch process which then tries to execute the contents of the folder . locally run it works on all wintel os and copies the files from \networkshare\folder*.* to %systemdrive%\temp\ .
I have attempted to use e.g psexec #serverlist.txt -c batfile.bat -s -f -d to copy the file and then execute it remotely how ever the issue is that this will not copy the files when run remotely . I think its a authentication issues after you a have remotely executed the batch file the remote system will not allow me to access/authenticate the networkshare
i have tried xcopy , copy , robocopy .
AFAIK you can only authenticate against the next hop using implicit credentials. Connection attempts from the first hop to a second hop will fail, even if your user has the required permisssions. See e.g. here for an explanation.
Try this:
psexec #serverlist.txt -u %USERDOMAIN%\%USERNAME% -d -c batfile.bat
Use explicit credentials so you're authenticated against the remote host. With that the second hop will be the next hop for your authenticated session. Don't run the script as LOCAL SYSTEM (-s), because that account is restricted to local resources.
I've had this issue in the past. Instead of trying to copy/run the BAT file just run the script things from a UNC path if you are able to. I think the problem lies in the BAT file not actually able to run through PSEXEC and copy like you think. Does it give an exit code?
Here's an example I used a while ago to install Adobe reader. I tried to do it through a batch file but no dice. I could not get it to run within the batch file whether I copied it or not. I can't remember the exact reason, I think it had something with the way a batch file is called in the system and runs in some sort of local context. Don't quote me on that though as I can't remember the exact why.
Here is my code example:
psexec /accepteula \\%computer% -s cmd /c msiexec /i "\\UNC\Software\adobe\Adobe Reader 7.0.9.msi" TRANSFORMS="acrobat7.mst" /qn

Problems Installing PostgreSQL 9.2

I've been trying to install the 64bit version of PostgreSQL 9.2 for Windows on my machine (Windows 7 64bit) and get this error:
The environment variable COMPSPEC does not seem to point to the cmd.exe or there is a trailing semi colon present.
I've installed it as Administrator.
I disabled the antivirus (Microsoft Security Essentials) and the firewall.
Running:
"%COMSPEC%" /C "echo test ok"
returned test ok
I've checked my System Environment Variables for trailing semi colon and I couldn't find any.
I then installed the 32bit version and managed to get to the end of the install with a different error message stating: Problem running post-install step. Installation may not complete correctly Error reading the C:\Program Files (x86)\PostgreSQL\9.2\data\postgresql.conf but there is no postgresql.conf file in that directory. It did install the application and when I try to connect the server with the red X on it it says fail at the bottom and it won't connect after I type in my password.
How can I connect to this server connection?
ComSpec is a generic error message for any installation failure.
Identifying the problem
Navigate to below path
c:\Users\XXXXXX\AppData\Local\Temp
Open 'bitrock_installer_XXXX.log'
Check, if you are getting below error:
Script stderr:
'"C:\Users\XXXXX\AppData\Local\Temp\POSTGR~1\TEMP_C~1.BAT"' is not recognized as an internal or external command, operable program or batch file.
Error running
C:\Users\XXXXX\AppData\Local\Temp/postgresql_installer_47b21c4ea1/temp_check_comspec.bat :
'"C:\Users\XXXXX\AppData\Local\Temp\POSTGR~1\TEMP_C~1.BAT"' is not recognized as an internal or external command,
operable program or batch file.
This is a problem with '8.3 file names and directories' (e.g. '\Postgres Install' -> '\POSTGR~1')
Microsoft article on disabling 8.3 file names and directories: https://support.microsoft.com/en-gb/kb/121007
Solution:
Open command prompt in admin mode
Execute following command to change the format based on your drive or all drives
Sample commands:
fsutil 8dot3name set 1" - disable 8dot3 name creation on all volumes
fsutil 8dot3name set C: 1" - disable 8dot3 name creation on c:
Execute the installation as a user having admin privileges
After install, consider resetting the 8dot3name setting to default (2) to avoid unintended consequences
Hope it solves the problem!
Very easy fix:
Just open Advanced System Settings in Control Panel and create a new System Variable( in the System Variable instead of User Variable section).
In the variable name, enter ComSpec and then in the variable value , enter C:\Windows\system32\cmd.exe.
Alternative fix:
If you have already the ComSpec variable in the System Variable section, remove the ;at the end of it this should fix it.
It's not COMPSPEC it's just COMSPEC. Please show the output of:
echo %COMSPEC%
Note that COMSPEC could be set to something different in the Administrator account you're running the installer as. I'm not sure how to find that out, but it might appear in the PostgreSQL installer log, so please upload that and link to it in your post. See Reporting an installation error for info on where to get the installer log.
See the PostgreSQL for Windows FAQ entry Check the COMSPEC environment variable.
Here's a report I made suggesting that the installer should test for this explicitly and here's my blog post on the topic.
I got the same problem, and i found in the log:
Script stderr:
'C:\Users\S300' is not recognized as an internal or external command,
operable program or batch file.
Error running C:\Users\S300 (i5)\AppData\Local\Temp/postgresql_installer_56caeadbd6/temp_check_comspec.bat : 'C:\Users\S300' is not recognized as an internal or external command,
operable program or batch file.
I change in User Variables TEMP to D:\TEMP and TMP to D:\TEMP.
And Solved My Problem.
In my case , the Installer was in %USERPROFILE%\DownloadsP{ Windows download folder}, I moved the installer to desktop and ran again. weird it worked lol.
I had a similar problem. After installation, the data folder contained no postgres.conf file. It only contained a single folder named "pg_log".
I described the solution that I used here: Postgres Installation Error reading file postgresql.conf
Basically, it would be helpful to check if the user has full permissions for the postgres folder, and run "init_db" and "pg_ctl start" commands again. If the path contains a space character, try using a relative path for the pg_ctl data folder argument.
I'm running Windows Server 2003 R2, and I have been unable to resolve this problem with the installer, so I resorted to using the binary PostgreSQL package. Hopefully this will be an alternative for others who do not want to perform an OS reinstall.
First, some background (hopefully useful to the developers)
It started out with the postgres service failing to start (the server had been running reliably for over a year). I assumed it was a corrupted PostgreSQL installation, so I uninstalled and attempted to reinstall. I encountered the following error:
There has been an error.
The environment variable COMSPEC does not seem to point to the cmd.exe or there is a trailing semicolon present.
Please fix this variable and restart installation.
However, the COMSPEC variable is set properly, verified with:
echo %COMSPEC%
C:\WINDOWS\system32\cmd.exe
and:
"%COMSPEC%" /C "echo test ok"
test ok
Since this is Windows Server 2003, there is no UCA wrapper around the Administrator account, so that is not causing the problem.
Manual Installation
NET USER postgres /ADD
C:\pgsql\bin\initdb.exe -U postgres -A password -E utf8 -W -D C:\pgsql\data
runas /user:postgres "C:\pgsql\bin\pg_ctl -D C:/pgsql/data -l C:/pgsql/logfile.txt start"
just do it run as administrator and change the environment system variable
like create a new variable 'ComSpec' and value type 'C:\Windows\system32\cmd.exe'.
If the installer exe is on a network share that mapped drive might actually not be accessible to the installer as it runs as administrator. This can often happen in some virtual machine arrangements such as running windows in a parallels VM. Copy the installer to a local drive first and you won't have a problem.
What worked for me after trying to enter the commandline given her in cmd.exe
I found it was named cmd1.exe in system32.. so i copied the file and renamed it as cmd.exe and installation finished
Open Environment Variables, you can do this on Windows 7 by typing environment variables in the Search program and files bar when pressing the start button at the bottom left of the desktop. And create a new System Variable(in the 'System Variable' instead of 'User Variable' section).
In the variable name, enter ComSpec and then in the variable value , enter C:\Windows\system32\cmd.exe.
That's all. Hope it works!
Alternative fix:
If you already got the ComSpec variable in the System Variable section, remove the ; at the end of it this should fix it.
First find the path to cmd.exe(mostly it is C:\Windows\System32\cmd.exe).
Go to the enviornment variable and add this path to system variable path.And also create new variable in user variable called ComSpec and add this path as value. And you are ready to go.

How do I set the path automatically on login when ssh'ing to a Windows machine?

I want to set the path on a Windows server so that when I log in via SSH the directory
C:\Program Files (x86)\Git\libexec\git-core
is in my path.
I can ssh to the server, but %PATH% does not contain the directory above.
Is there are file like ".profile", ".bashrc", or ".login" where I can add a directory to the path?
You can also set your path from the command line with
setx PATH "%PATH%;C:\Program Files (x86)\Git\libexec\git-core"
I'm having the same problem as you, though, which is my path is different when I'm at a command prompt at the keyboard vs logged in remotely. Still trying to figure that one out.

How to run batch file from network share without "UNC path are not supported" message?

I am trying to run a batch file from a network share, but I keep getting the following message: "UNC path are not supported. Defaulting to Windows directory." The batch file is located on \\Server\Soft\WPX5\install.bat. While logged in as administrator, from my Windows 7 Desktop, I navigate to \\Server\Soft\WP15\ and double click on install.bat, that's when I get the "UNC path are not supported." message. I found some suggestions online stating that mapping drive will not work, but using a symbolic link will solve this issue, but the symbolic link didn't work for me. Below is my batch file content, I would appreciate any assistance that can help me accomplish what I am trying to do. Basically, I want to be able to run the batch file from \\Server\Soft\WP15\install.bat.
Batch file content
mklink /d %userprofile%\Desktop\WP15 \\server\soft\WP15
\\server\soft\WP15\setup.exe
robocopy.exe "\\server\soft\WP15\Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s \\server\soft\WPX5\Custom\Migrate.reg
Also, how do I remove the symbolic link after the install is completed?
PUSHD and POPD should help in your case.
#echo off
:: Create a temporary drive letter mapped to your UNC root location
:: and effectively CD to that location
pushd \\server\soft
:: Do your work
WP15\setup.exe
robocopy.exe "WP15\Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s WPX5\Custom\Migrate.reg
:: Remove the temporary drive letter and return to your original location
popd
Type PUSHD /? from the command line for more information.
I feel cls is the best answer. It hides the UNC message before anyone can see it. I combined it with a #pushd %~dp0 right after so that it would seem like opening the script and map the location in one step, thus preventing further UNC issues.
cls
#pushd %~dp0
:::::::::::::::::::
:: your script code here
:::::::::::::::::::
#popd
Notes:
pushd will change your working directory to the scripts location in the new mapped drive.
popd at the end, to clean up the mapped drive.
There's a registry setting to avoid this security check (use it at your own risks, though):
Under the registry path
HKEY_CURRENT_USER
\Software
\Microsoft
\Command Processor
add the value DisableUNCCheck REG_DWORD and set the value to 0 x 1
(Hex).
Note:
On Windows 10 version 1803, the setting seems to be located under HKLM:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor
Basically, you can't run it from a UNC path without seeing that message.
What I usually do is just put a CLS at the top of the script so I don't have to see that message. Then, specify the full path to files in the network share that you need to use.
I needed to be able to just Windows Explorer browse through the server share, then double-click launch the batch file. #dbenham led me to an easier solution for my scenario (without the popd worries):
:: Capture UNC or mapped-drive path script was launched from
set NetPath=%~dp0
:: Assumes that setup.exe is in the same UNC path
%NetPath%setup.exe
:: Note that NetPath has a trailing backslash ("\")
robocopy.exe "%NetPath%Custom" /copyall "C:\Program Files (x86)\WP\Custom Templates"
Regedit.exe /s %NetPath%..\WPX5\Custom\Migrate.reg
:: I am not sure if WPX5 was typo, so use ".." for parent directory
set NetPath=
pause
Instead of launching the batch directly from explorer - create a shortcut to the batch and set the starting directory in the properties of the shortcut to a local path like %TEMP% or something.
To delete the symbolic link, use the rmdir command.
I ran into the same issue recently working with a batch file on a network share drive in Windows 7.
Another way that worked for me was to map the server to a drive through Windows Explorer: Tools -> Map network drive. Give it a drive letter and folder path to \yourserver. Since I work with the network share often mapping to it makes it more convenient, and it resolved the “UNC path are not supported” error.
My situation is just a little different. I'm running a batch file on startup to distribute the latest version of internal business applications.
In this situation I'm using the Windows Registry Run Key with the following string
cmd /c copy \\serverName\SharedFolder\startup7.bat %USERPROFILE% & %USERPROFILE%\startup7.bat
This runs two commands on startup in the correct sequence. First copying the batch file locally to a directory the user has permission to. Then executing the same batch file. I can create a local directory c:\InternalApps and copy all of the files from the network.
This is probably too late to solve the original poster's question but it may help someone else.
This is the RegKey I used:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"DisableUNCCheck"=dword:00000001
My env windows10 2019 lts version and I add this two binray data ,fix this error
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor DisableUNCCheck value 1
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Command Processor
DisableUNCCheck value 1
This is a very old thread, but I still use Windows 7. :-)
There is one point that no one seems to have taken into account, which probably would help Windows 10 users also.
If Command Extensions are enabled, the PUSHD command accepts network paths in addition to the normal drive letter and path.
So the obvious - and simplest - answer might be to enable command extensions in the batch script, if you intend to use PUSHD. At the very least, this ought to reduce the problems you might have in using PUSHD wqith a network path.
I stumbled upon this question while searching for a solution to a specific problem. I needed to make a batch script that sits in a network folder (UNC path) with a Python script. The goal was to be able to double click on the batch script and have it run the Python script:
with the network folder containing the script as the working directory,
without modifications to the Python script (no command line parameters or hard-coded paths).
without creating another Python file.
The pushd and popd solutions were unsatisfactory. They work, but if the user were to get in the habit of forcefully terminating the script while it was running, they would end up with a bunch of mapped drives in My Computer since popd wasn't run.
I start by using cls to clear the UNC path error. I then assign the path containing the batch script to a variable. I slice the path to remove the trailing backslash (otherwise, Python throws a SyntaxError). Finally, I run a couple Python commands inside the batch file that change the working directory and execute the target script:
cls
#echo off
set pyfile=myscript.py
set batchdir=%~dp0
set wdir=%batchdir:~0,-1%
python -c "import os; import runpy; os.chdir(r""%wdir%""); runpy.run_path(r""%pyfile%"")"
pause
Editing Windows registries is not worth it and not safe, use Map network drive and load the network share as if it's loaded from one of your local drives.

Problem with relative paths(*.bat + VMWARE + Windows 2003)

This may be a question for ServerFault but I was more interested in understanding the methodology that the OS uses to resolve relative paths. I have two VMware instances of Windows 2003. I am trying to run a batch file that starts running another batch file within its folder path. The script runs fine on one VM but on the other VM it fails to execute with the error:
> The System cannot find the file specified
The script I am trying to run is script.bat:
start /d FOLDERNAME /b /WAIT AnotherScript.bat %~n0%~x0
I have put both my files within the same folder structure under the C:\ drive on both machines. The file AnotherScript.bat resides within FOLDERNAME on both the VMs.
It is not a permissions issue(?) since I show up as an administrator on both VMs.
I was wondering why would I get an unable to resolve relative paths on one machine vs. the ability to resolve it on another machine.
Thanks
First check if the folder in which both are lauching are the same. Try adding ECHO %CD% before calling the 2nd script to check the directory in which it is getting launched.
Also check if the path where the 2nd bat file resides is set in the %PATH% variable in the 1st VM.
Where does command prompt start by default in both VMs?

Resources