I'm trying to run a batch file from a local Windows server that calls on computers in my domain to pull from the shared folder and run an exe. I'm not sure if my script is trying to do too much or too little.
So I run the below batch locally
X:\pstools\psexec.exe \\Computer -d -u DOMAIN\user -p password -i \\SERVER\test\testfile.bat
and testfile.bat:
#echo off
pushd \\SERVER\test\
call program.exe
popd
When I run the script, psexec runs and I get a confirmation that testfile.bat was started on target computer. On the targeted computer nothing happens. If I navigate to the share on the targeted computer and run testfile.bat, I get "CMD.EXE was not started with the above path as the current directory.UNC paths are not supported. Defaulting to Windows directory." From there the computer runs the called .exe with no issues.
If I target this towards another server in my domain it executes perfectly, but not on domain computers. I thought maybe a GPO issue, but I can't find a solution.
Thanks for any knowledge or help provided!
Thanks for all the tips everyone! This is how I ended up getting it working for anyone who might have the same issue.
Script on Server:
x:\pstools\psexec.exe \\Computer(or text file with computers listed) -d -s cmd /c (batchfile.bat)
Similiar to what I was trying before, but to ensure you run the command line as System on the remote PC you have to specify "-s cmd". The /c copies the batch to the remote system to run locally. You can include a "-f" to overwrite if you've already copied it previously. I just put the batchfile in the pstools folder.
Batchfile.bat:
pushd \\networkdrive
call (.bat/.cmd/.exe/etc.)
popd
I disabled the firewall for testing, but I believe you have to open TCP-445/UDP-137 for PSEXEC. Otherwise, that's it. Super simple solution.
I am trying to extract a zip file in Windows 10 using a batch script.
It a simple command:
tar zxf "logstash-5.4.0.tar.gz"
ECHO "installed"
But I am getting following error:
'tar' is not recognized as an internal or external command
I have seen that I have to install the tar but how can I do that?
How can I do this?
EDIT Tar is pre installed in windows or we have to externally add it? Still how can i extract without using third party tool.
You can download Tartool Application in your desktop and paste it into
C:\Windows\system32\
For eg:-(C:\Windows\system32\tartool.exe)
By doing this it work as internal command when you want to extract your file you can simply use
C:>TarTool.exe D:\sample.tar.gz ./
For more commands you can read documention part of that Tool
Starting windows 10 build 17063, TAR is an inbuilt tool and no need to install it separately. MSDN link
For example, to uninstall a file named XYZ.zip you can execute the following in Command Prompt.
tar -xvf XYZ.zip
I'm trying to set Git executable in IntelliJ to be the git installed in Windows Subsystem for Linux, I tried a few different ways, but always got some sort of error. Today I installed to Creators Update (Version 1703), reinstalled WSL and tried again, here's what I did:
I created a .bat script:
#echo off
C:\Windows\System32\bash.exe -c "git %*"
So when running it:
C:\Users\Limon\Desktop>bash.bat --version
git version 2.7.4
So then I tried to set this bat at the git executable in IntelliJ:
And it worked! But everything else fails, for example when I try to pull or branch in IntelliJ, I get:
Couldn't check the working tree for unmerged files because of an error.
'C:\Windows\System32\bash.exe' is not recognized as an internal or external command,
operable program or batch file.
Any ideas on how fix this? I don't really know anything about batch scripting. It works perfectly off command line.
I was looking for a way to use git on WSL Windows Subsystem for Linux through Webstorm or an IntelliJ idea software.
I tried KatoPue's solution, but I got the following error:
fatal: could not read log file 'C:/Program Files/Git/mnt/c/Users/Elies/AppData/Local/Temp/git-commit-msg-.txt': No such file or directory
I solved it by replacing the path when sending the command to WSL's git
Settings > Version Control > Git > Path to Git executable : path_to_wslgit.bat
wslgit.bat :
#echo off
setlocal enabledelayedexpansion
set command=%*
set find=C:\Users\%USERNAME%\AppData\Local\Temp\git-commit-msg-.txt
set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt
call set command=%%command:!find!=!replace!%%
echo | C:\Windows\Sysnative\bash.exe -c 'git %command%'
Since WebStorm 2020.2 EAP it is possible.
Just add \\wsl$\YOUR-WSL-VERSION\usr\bin\git to the Path to Git executable:
To get your WSL VERSION type in a console wsl -l
In PyCharm 2018.1 I got various errors, when trying to settled up Git. I've to combine different approaches to make it run. Next code works for me:
#echo off
setlocal enabledelayedexpansion
set command=%*
If %PROCESSOR_ARCHITECTURE% == x86 (
echo | C:\Windows\sysnative\bash.exe -c 'git %command%'
) Else (
echo | bash.exe -c 'git %command%'
)
UPD:
Now is available integration with Git inside WSL through WSLGit wrapper. I've checket it out with PyCharm and it's work like a charm. Here is a link https://github.com/andy-5/wslgit
Change the double to single quotes.
You can log, what arguments are fed to your bat file
#echo off
#echo %*>> %~dp0log.txt
bash.exe -c 'git %*'
With that, i discovered i had some escaping problems.
FYI: With the Win10 creators update piping bash and spawning it from Windows programs works fine.
In PhpStorm (2017.2 EAP) I get error
Caused by: com.intellij.openapi.vcs.VcsException: 'bash.exe' is not recognized as an internal or external command, operable program or batch file.
For solution i change last line to
If %PROCESSOR_ARCHITECTURE% == x86 (
C:\Windows\sysnative\bash.exe -c 'git %command%'
) Else (
bash.exe -c 'git %command%'
)
For me this solution works:
File: git.bat
#echo off
setlocal enabledelayedexpansion
set command=%*
If %PROCESSOR_ARCHITECTURE% == x86 (
C:\Windows\sysnative\bash.exe -c 'git %command%'
) Else (
bash.exe -c 'git %command%'
)
As Gabrielizalo answered earlier, you need to use version 2020.2 and higher.
Go to Settings | Version Control | Git
Add \\wsl$\YOUR-WSL-VERSION\usr\bin\git to the Path to Git executable
Press Test
Please note, if you are using the WLinux distribution, you need to use the name Pengwin.
Even though the wsl -l command outputs the name as WLinux. Perhaps It will be fixed in future versions.
This is how it works for me \\wsl$\Pengwin\usr\bin\git.
If you are still having problems with Pengwin (WLinux). You need to reimport it as Pengwin.
Follow this instruction:
Restart your system.
Open PowerShell as administrator.
wsl --list. You will see a list of distributions, including WLinux (Default).
Make a backup with command wsl --export distro_name file_name.tar.
For example, wsl --export WLinux E:\backup.tar. It will take some time, as the distribution can reach several gigabytes.
Make sure the backup is complete, then remove the distribution from WSL with the command wsl --unregister WLinux.
Next, reimport the distribution with name Pengwin
wsl --import distro_name install_location file_name.tar, e.g.,
wsl --import Pengwin C:\Users\<USERNAME>\pengwin E:\backup.tar
Set the distribution as default wsl --setdefault Pengwin
To run default WSL distro as the specified user use wsl --user <Username>
Add \\wsl$\Pengwin\usr\bin\git to the Path to Git executable to your IDE, and press Test
Note, now when using pengwin in cmd, or from the Start menu, a new Pengwin instance will be installed. You can check this with the wsl --list command. The new instance will show up as WLinux. If you accidentally create a new instance, you can delete it with the command wsl --unregister WLinux.
For the convenience of using your distro, I strongly recommend installing a custom terminal. You can follow this guide How to setup a nice looking terminal with WSL in Windows 10.
Worked till PHPSTORM 2018.3 (or maybe a Windows Update changed some behavior regarding bash.exe). I am using Ubuntu 18.04 LTS. However, the path of my bash.exe changed - it is no longer in C:\Windows\Sysnative\bash.exe.
To get things working again I modified Elies Lou's wslgit.bat and set new path for bash.exe:
#echo off
setlocal enabledelayedexpansion
set command=%*
set find=C:\Users\%USERNAME%\AppData\Local\Temp\git-commit-msg-.txt
set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt
call set command=%%command:!find!=!replace!%%
echo | C:\Windows\System32\bash.exe -c 'git %command%'
I updated the soultion to work with WSL2 with a network drive and PhpStorm 2019.2.
wsl_git.bat:
#echo off
setlocal enabledelayedexpansion
set command=%*
set find=C:\Users\%USERNAME%\AppData\Local\Temp\git-commit-msg-.txt
set replace=/mnt/c/Users/%USERNAME%/AppData/Local/Temp/git-commit-msg-.txt
call set command=%%command:!find!=!replace!%%
echo | wsl CURDIR="%cd%"; STR2=${CURDIR//\\//}; STR3=${STR2/U:/}; cd $STR3; git %command%
It replaces the path in command for git-commit-msg-.txt to be able to commit as it was mentioned in other answers.
With WSL2 I use the network drive: \\wsl$\<distro_name> -> U:\. My project has path on Windows: U:\home\roman\projects\experiments, but on Linux it is /home/roman/projects/experiments. PhpStorm uses path from Windows to work with git, so it is needed to change path which can be reachable in the Linux subsystem. To achieve this I replace slashes \ -> / (STR2) and remove drive name U: -> `` (STR3) then change current dir to this modified path.
Install your project file in the wsl file system , any way you'll need this iff you go docker ;p
Open your project from \wsl$
(if needed) Go to Settings > Version Control > Git > and simply clear the Path to Git executable
and this work so fine !
I have downloaded solr 6.4.0 version and tried starting using solr start from bin directory I end up with following error:
C:\solr-6.4.0\bin>solr start
'findstr' is not recognized as an internal or external command,
operable program or batch file.
C:\solr-6.4.0\bin>
Could you please advise me is there any configuration that i need to do/ how to start?
Thanks.
The program findstr.exe can be found in C:\Windows\system32.
Check if you can find it there.
If it is available, modify your "path" environment variable to include the path "C:\Windows\system32\".
If you have an open command prompt window, exit and re-open it, and check that the %PATH% variable contains the newly added path.
echo %PATH%
Now "findstr.exe" should be available for Solr scripts.
Download solr + copy downloaded folder to c: drive (solr7.2.1)
Download nssm installer + copy downloaded folder to c: drive (solr)
open nssm installer in cmd:
>> cd C:\solr\nssm2.24\win64
>> nssm install solr7
GUI service Installer opens (Enter solr path details)
- C:\solr-7.2.1\bin\solr.cmd
- C:\solr-7.2.1\bin
Install (solr as service gets installed)
Set Environment Variable -> System Variables (JRE Path):
JAVA_HOME: c:\ProgramFiles\java\jre1.8.0_212
Check if solr is running (from services)
Open Solr:
https://localhost:8983/solr/#/
Actually findstr.exe is missing.
So follow these steps:
1.go to C:\Windows\system32\ and copy findstr.exe file.
2. paste this file into the location C:\Program Files\Java\jdk{version}\bin
Then run the this command:
solr.cmd start
Hope this helps.
I need to create WinRAR SFX archive that should work with admin permissions on Windows 7. I can make it with WinRAR GUI but I need to make it with WinRAR command line interface (to integrate it into build process).
At the moment my script is like that:
rar.exe a -sfxdefault.sfx archive.exe some_file_to_be_in_sfx
rar.exe c archive.exe -zscenario.txt
while scenario.txt is
TempMode="Extract data from archive?","Title"
Any suggestions are welcome!
First, take a look on question How can I automate the building of this Winrar Sfx File.
Second, if you have open the tab Advanced of Advanced SFX options dialog with the option Request administrative access in WinRAR GUI, there is a button Help which opens the help page for this dialog. This help page contains:
Request administrative access
Set this option if you wish to create SFX archive, which will request the administrative access when started in Windows Vista and later. This option does not change behavior of SFX archive in older Windows versions.
Corresponding command line switch is -iadm.
And this answers your question. -idam is on help page a hyperlink to the help page of this switch.
But the text file Rar.txt in program files folder of WinRAR containing an explanation of all commands and switches supported by console version Rar.exe does not list this switch nor does Rar.exe output it on running it from within a command prompt window with no parameters to get displayed the help for console version.
This means only WinRAR.exe supports the switch -iadm, but not console version Rar.exe. But this is no problem as WinRAR.exe can be executed also from within a batch file from console, best with using background process option -ibck.
Note: Best on creating the command line for WinRAR.exe is opening in help the page Alphabetic switches list via Contents - Command line mode - Switches and read from top to bottom while building the command line. Add the switches you need for creating the SFX archive.
For example:
WinRAR.exe a -cfg- -ep1 -iadm -ibck -inul -k -m5 -ma4 -md4m -r -s -sfxdefault.sfx -tl -y -zscenario.txt archive.exe some_file_to_be_in_sfx
May be Its too late to answer this Question but Simple solution to this is command
"C:\Program Files\WinRAR\WinRAR.exe" a helpTestUpdate -s -sfx logFile.txt
This will take the logFile.txt and convert it to the .exe sfx file.