I need to start an application by running "Run as Administrator". I have been searching for the command line and tool, it seems psexec.exe able to provide this functionality.
However, I have no success running it.
psexec -u myowndomain\david123 -p myPassword1 "E:\Temp\StartUp.exe"
I do not need to run remote computer. I just want to simulate the "Run as Administrator" when I do it manually.
Is the command correct ? Thanks.
There is a runas command, you can read more there: RUNAS
runas [{/profile | /noprofile}] [/env] [{/netonly | /savecred}] [/smartcard] [/showtrustlevels] [/trustlevel] /user: " "
Related
I'm trying to use sqlcmd to execute querys on a remote database but I can´t login
When I connect using SSMS i have to use this runas command
runas /user:domain\username /netonly "Ssms.exe"
How can I log in like that using sqlcmd?
I´ve tried "-U domain\username -P password" and "-E" but none of those work.
I've also tried
runas /user:domain\username cmd.exe
to run cmd and then use sqlcmd from there but it says cmd.exe cannot be executed.
Thanks in advance!
Its almost certain that HTA files are obsolete, but i've found that they are much better than net send / msg.
I'm trying to run a HTA file on a remote machine using PSTools, but instead of it running, it brings back a broken window:
Running the HTA file using CMD (locally) works perfectly though.
My PsExec line:
PsExec.exe -accepteula -i -d \\itwall cmd 'mstha \\intranet\Downloads\VisitorSystemNewMessage.hta asd'
I even tried to run the HTA from a Batch file, but the exact same thing happens.
Any ideas?
It's because the account running the command cannot interact with the session of the remote user.
Use the -s switch to run the HTA using the system account of the remote computer.
Also, you shouldn't need to run cmd. You should be able to just specify mshta.exe then your arguments.
PsExec.exe -accepteula -s -i -d \\itwall mshta.exe \\intranet\Downloads\VisitorSystemNewMessage.hta asd
Edit: To illustrate that this is not an HTA issue. Run the following command:
PsExec.exe -accepteula -i -d \\itwall notepad.exe
Notice you'll have the same black window showing.
I have question how run file .bat as admin? How run cmd as admin in file bat?
I must run command on cmd:
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -px "MyKey" c:\key.xml -pri
Please help and have any tips or any good material.
Use RUNAS command for this purpose like below. See help using runas /? in command prompt
runas /user:administrator "%windir%\Microsoft.NET\Framework\v2.0.5
0727\aspnet_regiis.exe -px "MyKey" d:\key.xml -pri"
Enter the password for administrator:
open start menu by pressing windows key type cmd right click cmd and select Run as administrator this will open the command prompt in administrator mode and then you can run your command as an administrator.
I am using Jenkins on a Windows7 system. I would like to use it to execute a batch script on a remote Windows system. The batch script will be used to flash a development board and run some tests. I came across psexec.exe. That works well through a command prompt window--I can connect and run the script without any issues, but when I try to have Jenkins do it, I get the following output:
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Connecting to ABCDEFG...
Couldn't access ABCDEFG:
Connecting to ABCDEFG...
Build step 'Execute Windows batch command' marked build as failure
The command I am using in both cases is:
psexec.exe \\ABCDEFG -u "DOMAIN\username" -p "password" "C:\test.bat"
The user associated with username has administrator privileges on the remote system (ABCDEFG is not the real name of the system).
Can anyone help me figure out why it is not working through Jenkins? Or, is there an easier/better way to execute a batch script on a remote Windows system through Jenkins?
Thanks to all your help, especially Technext, I have a solution.
I needed run "services.msc", find "Jenkins", right click on it, and go to "Properties". Once the properties windows appeared, I had to click the "Stop" button to stop Jenkins, open the "Log On" tab, enter in my username and password (the username I used when running through command prompt), and start Jenkins again. That got rid of the "handle is invalid" message in Jenkins.
Update:
A better solution was to go onto the system I was using psexec.exe to get onto, go to Control Panel > User Accounts > Give other users access to this computer. Click on "Add..." and type in the username and domain Jenkins uses to run its commands (to find this, open your Jenkins in a browser window, go to Manage Jenkins > System Information and look for USERNAME and USERDOMAIN under Environment Variables). Make sure you give it Administrator rights. Then click ok. Now psexec.exe shouldn't have the "handle is invalid" issue.
Sorry, I don't have enough reputation for comments, but is the single \ a typo? Since
The handle is invalid.
probably means that the computer address is invalid. Try
psexec.exe \\ABCDEFG -u "DOMAIN\username" -p "password" "C:\test.bat"
Notice the two backslashes to access a locally mapped computer.
otherwise if that does not work i recommend the # tag
psexec.exe #servername.txt -u "DOMAIN\username" -p "password" "C:\test.bat"
where #servername.txt is a textfile containing only the servernames, one per line. The file parameter handles the formatting of \
ex servername.txt
ABCDEFG
COMPUTER2
EDIT: also found after some quick googling that it can be related to windows security.
Check out that a simple restart of the remote machine doesn't solve the problem. Also, adding parameters -h and -accepteula may help. Modified command:
psexec.exe \\ABCDEFG -u "DOMAIN\username" -p "password" -h -accepteula "C:\test.bat"
I execute below code from Jenkins pipeline groovy script to connect dynamically created VM as a resource on Jenkins master. Below code connect dynamically created VM as resource on Jenkins master with 4 executors. You can change the number of executors based on your requirement.
bat label: 'ConnectResource', script: """
#echo OFF
C:\\apps\\tools\\psexec \\\\${machine_ip} -u ${machine_ip}\\${machine_username} -p ${machine_password} -accepteula -d -h -i 1 cmd.exe /c "cd C:\\apps\\jenkins\\ & java -jar C:\\apps\\jenkins\\swarm.jar -master http://pnlv6s540:8080 -username ${jenkins_user_name} -password ${jenkins_user_password} -name ${machine_ip}_${BUILD_NUMBER} -labels ${machine_ip}_${BUILD_NUMBER} -deleteExistingClients -disableClientsUniqueId -executors 4" & ping 127.0.0.1 -n 60 > nul
"""
I want to execute a bat file in a remote machine and i tried WMI and PSEXEC. I am getting "No process is on the other end of the pipe." error when i try to run the below psexec command.
C:\Users>psexec \\111.111.111.111 -u "sss\user1" -p "ss-12" "\\111.111.111.111\d$\r.bat"
Below is the entire output:
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com
Connecting to 111.111.111.111...
Starting PSEXESVC service on 111.111.111.111...
Connecting with PsExec service on 111.111.111.111...
Error reading public key length from PsExec services:
No process is on the other end of the pipe.
However, the below WMI command is working fine. Please help.
wmic /USER:"sss\user1" /PASSWORD:"ss-12" /NODE:111.111.111.111 process call create "D:\r.bat"
Try stopping the PSEXESVC service.
pskill \\HOSTNAME PSEXESVC
In your case you would run:
pskill \\111.111.111.111 -u "sss\user1" -p "ss-12" PSEXESVC
Got the same issue.
I have found 2 workarounds, which are both not acceptable if you are running your remote machines/servers in production.
First workaround: reboot the machine. It solved the problem 80% of the time.
Second workaround, in powershell run:
sc.exe stop PSEXESVC
Remove-Item –path 'C:\Windows\PSEXESVC.exe'
Remove-Item -Path hklm:\SYSTEM\CurrentControlSet\Services\PSEXESVC -Confirm:$false
Then reboot.
After I run some more PSEXEC commands, the problem appears again. Will update if I find a solution.