I am shelling in the a few push d statements based on a list of users from the active directory. 2 for example are
java.exe -version
and
dir /s
The search actually seems to search the actual computer and output the files from their directory. However, the java.exe only outputs the actual output from the computer that it is being ran on.
Is this even possible to run a remote exe from the pushd statement? Any thoughts would be great.
Here is the code as of right now in a simplified version. Let me know if anyone would like more.
Dim sCommand as String = "pushd \\***\C$ && java.exe -version 2>>C:\Testfile.txt"
Dim sCommand2 as String = "pushd \\***\C$ && dir /s blah.blah>>C:\Testfile.txt"
For each SelectedItem in Listbx.SelectedItems
Dim ReplaceCommand as String = sCommand.Replace("***", SelectedItem)
Shell("cmd.exe /c" & ReplaceCommand, True)
Dim ReplaceCommand as String = sCommand2.Replace("***", SelectedItem)
Shell("cmd.exe /c" & ReplaceCommand2, True, -1)
Next
To me, you'll need to find on the remote computer first the location of the JAVA executable. Your commands you're executing on the shell will search your local defined paths, not the remote paths.
Consider this.
first execution is local > running java 1.6.0.23
then I pushd to another computer. I re-execute the same command.
Since i'm not in the remote directory containing the java.exe file, it'll process my path to find it. >same version is returned
I then change to the remote's Java container and re-execute the statement.
This time it's finding the remote Java.exe and processes the command.
Related
I want to install license for my PC. However, I can't add parameter for the method.
My code:
#echo off
for /r "%SystemRoot%\system32\spp\tokens" %%f in (*.xrm-ms) DO (
wmic path SoftwareLicensingService WHERE (Version is not null) call InstallLicense License='<%%f'
)
pause
Like I want to read all text in the files of "tokens" directory and send it to License parameter.
Here is VB code. I can do it in VB but not in .bat file (Batch)
Dim files As String() = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spp\tokens", "*.xrm-ms", SearchOption.AllDirectories)
wmic = New ManagementObjectSearcher("SELECT Version FROM SoftwareLicensingService").Get()
For Each i As String In files
For Each wmi As ManagementObject In wmic
wmi.InvokeMethod("InstallLicense", {File.ReadAllText(i)})
Next
Next
Thanks all. Sorry for my bad English because I'm Chinese :(
How can I run J scripts from the console (cmd.exe or Powershell).I tried to set the path to jconsole.exe in Environment Variables but when I tried to launch it via cmd.exe, I get an error message that 'jconsole' is not recognized as an internal command or... I have done this successfully in the past for different command line tools.
Also, how do I set the default directory in J so that I don't have to type the full directory path every time I run a file.
jconsole.exe works just like any other application in that regard. Once you've added the path to the file in your PATH variable, you can run it in a cmd session without specifying the whole path.
In my case, if I open cmd.exe and add the path to J binaries to my PATH (be sure not to add any quotes!):
set PATH=%PATH%;C:\Program Files\j901\bin;
Then check that it has been successfully added to the end by typing PATH and pressing Enter. Then I can successfully start J in that session by just typing jconsole.exe.
Note that this will only work for the current instance of cmd.exe. If I want it be available every time I open a new cmd.exe session, the I'd add it to the Path variable for my User using the Environment Variables Settings.
You mention that you've tried setting the path in Environment Variables, but it might be worth explicitly stating the directory where J is installed on your computer and what you've added to the PATH.
Have you confirmed in your cmd.exe session, that the path has been successfully amended?
I have a vb.net application that runs cmd.exe as the following:
Dim Port1 = CreateObject("WScript.Shell")
Port1.Run("cmd.exe")
Port1.Sendkeys("telnet ip address")
Port1.Sendkeys("{Enter}")
System.Threading.Thread.Sleep(6000)
When the cmd runs the sendkeys a error shows
"'telnet' is not recognized as an internal or external command,
operable program or batch file."
I closed the cmd window, opened another cmd, and typed in the command with not problems.
I need cmd to run in the vb.net and not as a separate file.
Running the vb.net in Microsoft visual studio Ultimate 2013.
Update: Can anyone tell me why it is doing the same thing when i move the app to another computer and try to run it?
You have to enable telnet on the computer by going to start > control panel > programs and features > turn windows feature on or off > check telnet client or typing optionalfeatures in run and checking telnet client. The command should execute successfully after that.
Either Telnet is not installed on your computer (it's not installed by default on any modern Windows versions as far as I know), or it its installation directory not in the PATH environment variable.
Either add it's install directory to PATH, or specify the full path to telnet.exe in the arguments to cmd.exe.
CMD runs commands based off of System32 and .bat(batch) or .exe. You would have to create a .exe or a .bat and place it into System32 in order for the command to work.
I'm new to WIMC so probably there will be simple answer to my question.
If I will open CMD and run this command:
wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%Windows%'" get DisplayName,Name,PathName,State,StartMode
this will generate file with all services not in windows folder.
If I will save above command in bat file and run this will generate list all services somehow ignoring WHERE statement. Running this as Administrator not changing anything.
In a batch script you have to double pump the % signs so they'll be treated as literal percent signs. Change your command to this and it'll work:
wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%%Windows%%'" get DisplayName,Name,PathName,State,StartMode
I need to start a document on a remote computer instead of an executable file, using PSExec.
I tried to provide the file name of a jpg file to psexec associated with the -c command to copy the file, but the message returned for documents (and not executables) is always "The system cannot find the file specified."
Anyone any ideas what the command-line for psexec should be?
Try to use the command:
cmd.exe /c START c:\path\to\document.jpg
Document must be on the remote computer, so you have to copy it there by other command before calling psexec.
Pick a program on that other machine that can show the JPEG and execute that, passing to it the path and name to the file you want to show.
As you've noticed, file associations doesn't work with remote execution like that, so you need to invoke the correct program instead.
In order to open a remote program and not only activate its process you have to use PSEXEC
with the -i (Interactive Mode) and MUST define the session number.
For example:
Usually on a Win7 host:
Console = Session 0
System = Session 1
User = Session 2
In order to activate and open notepad.exe on this remote Win 7 host use the following syntax:
psexec -i 2 \\ComputerName -u User -p Pass notepad.exe
Regards,
Shai Ziv
shaix.ziv#intel.com
This is the way that worked for me:
I've logged on to the via RDP:
I've copied a picture to the to "C:\Users<MyUserName>\Pictures\smiley.png"
I've opened a new powershell-window, typed "tasklist" and found out my windows session id (I simple took the highest session id I've found)
Back on my own PC:
I've downloaded PSTOOLS from https://download.sysinternals.com/files/PSTools.zip
I've unpacked PSTOOLS and placed it in "C:\Program Files\PSTools"
I've opened a new powershell-window and typed: cd "C:\Program Files\PSTools"
Finally i've started the remote PAINT with:
"C:\Program Files\PSTools\psexec" -s -i 4 "\\[RemoteComputerName]" "C:\Windows\system32\mspaint.exe" "C:\Users\[MyUserName]\Pictures\smiley.png"
P.S.: Don't forget to replace [RemoteComputerName] and [MyUserName]