PSExec could not start Regedit.exe on remote PC - psexec

Background:
I have several registry keys that are saved and used to update/configure remote PCs in my environment. I may not have deployed the device, previously, but I use these registry keys to update the PC as I fix/repair/etc...I am part of a team of 45 managing about 25,000 workstations and peripherals in our region of the enterprise.
if I use this command from my Win 10 PC to a Win 7 PC, it executes without problems.
psexec \remotecomputer -u domain\adminaccount regedit.exe /i /s "\server\share\directory1\directory2\directory3\someregistry.reg"
psexec starts regedit, imports the above registry file and closes.
If I run that exact same command from my Win 10 PC to another Win 10 PC, I get the following error, from CMD as ADMIN,
"PsExec could not start regedit.exe on REMOTEPC_HOSTNAME:
The system cannot find the file specified."
it can't find regedit??? WTF??
I'm curious why Win 10 is blocking me, as an admin, from importing a registry key?
I've tried reg import as a solution, but I keep getting syntax errors and it can't find the file/pathway.
It's almost like the remote PC, doesn't recognize admin input due to UAC settings?
In testing, I've set the group policy editor to enable remote registry tools, no change. I've enabled remote registry services and set to start the service automatically. I can access the PC registry via remote registry...but psexec just won't work on the remote device.
I can RDP to the device and run the command line equivalent:
regedit.exe /i /s "\UNC\pathway...\etc*.*reg" it executes, without issues.
this proves that regedit is working
Can anyone provide some expertise on this?

add -s flag to psexec to run regedit

The old PsExec trick of running RegEdit doesn't always work. This is because psexec depend on a hidden SMB Administrator service. (Which in any security sense should be disabled.)
PsExec allows redirects of the input and output of a remotely started
executable through the use of SMB and the hidden $ADMIN share on the
remote system. With this share, PsExec uses the Windows Service
control Manager API to start the PsExecsvc service on the remote
system which creates a named pipe that PsExec communicates with. This
named pipe is what allows for input/output redirection back to the
system that launched PsExec.
So instead, in order to remove any TrustedInstaller owned registry Keys, you can use a different tool. This worked:
ExecTI - Run as TrustedInstaller
Run it to open the ExecTI GUI and enter: C:\Windows\regedit.exe

Related

How do I run cygwin ssh properly on powershell?

My OS is Windows 10 (x64) and I installed both Powershell 7 and cygwin.
Then, I installed "sshpass" using cygwin.
And, here are the cases I am experiencing right now.
From cmd, if I enter "C:\cygwin64\bin\mintty.exe -", cygwin pops up with initial directory "~". Then, if I type "sshpass -p<password> ssh <username>#<host>", it perfectly works smoothly!
From cmd, if I enter "C:\cygwin64\bin\mintty.exe", cygwin pops up with directory "/cygdrive/c/Users/myname". Then, if I type "sshpass -p<password> ssh <username>#<host>", it asks me to type the password. This means that sshpass is not working correctly here.
From powershell, if I type "C:\cygwin64\bin\sshpass.exe -p<password> C:\cygwin64\bin\ssh <username>#<host>", nothing happens.
My questions are the following:
How do I properly run sshpass command in Powershell?
Let's say my ip address is 1.1.1.1 and I am connecting to a server whose ip is 2.2.2.2, and both computers OS systems are Windows. When I connect to the server through ssh, it shows the "cmd" terminal of the server. How can I change it to show "cygwin" terminal when I connect to the server?
I am having very hard time fixing this out.. Thank you very much in advance..
I am not sure i am getting this, anyway, if i understand correctly you have a hard time launching sshpass from powershell.
Try using Start-Process commandlet: (maybe add the full path to ssh in arguments (?))
start-process -filepath C:\cygwin64\bin\sshpass.exe -ArgumentList '-p<password> ssh <username>#<host>' -Wait -NoNewWindow
Anyway instead of reaching linux commands to windows and run it from powershell, why don't you check powershell modules?
ssh using powerShell script by passing the password along with the Commnad
Also, Powershell Remoting towards linux is a thing nowadays, and it runs over ssh (not bash afaik)

TeamCity BuildAgent does not see the network drive

I want to copy the file to a network drive using build agent (powershell or cmd (Build Steps)).
P:
# or
cd P:\foolder\
# ...
But the commands don't work. Build log: "Disk P not found".
The disk is connected via windows. When running from windows, the commands work.
I assume java/BuildAgent doesn't have rights. But my user has rights. And java, and BuildAgent runs under my user.
Please, do not offer FTP
Open command prompt as Administrator
bind your drive again using below command
net use x: \\10.1.2.3\Share
again do the same in Command prompt without administrator (if its not bounded)

Installing interactive msi in Remote Machine with Powershell

I have a .msi file in my remote machine which is in a different domain from my local machine. I am able to connect to the remote machine with powershell but how can I install the msi there. The installation process has a lot of inputs to be given along with pressing 'Next' and then again giving a particular input and radio buttons and many more. Thus it is an interactive installation. In my local I am able to do it with [System.Windows.Forms.SendKeys] to imitate the keyboard inputs but as the process will be running in background in the remote machine I don't think SendKeys will work. And 'psexec' is not an option here because in my remote machine I cannot include PSTools with my Powershell. Is there any way to do it with Invoke-Command and -ArgumentList??
If there is a way then how can I choose sequentially whether to input a text in a particular field or click the next button or click any other button within the application window??
I finally got to solve this puzzle with the help of a automation tool called AutoIt. This tool has its own scripting language and can create .exe files to run a particular application and do the corresponding installation steps based on each successive window the application installer pops. After creating the .exe I copied it to my remote machine using Copy-Item or you can use robocopy, then invoked the .exe remotely with the help of psexec. As I had the misconception previously about psexec, it only needs to be integrated with powershell at the local and thus it automatically creates a session of its own and interacts with the remote machine. This is the command to run the .exe on remote machine:-
psexec -i 2 -s -d \\remote_machine_name -u Username -p Password C:\Path_to_exe\installer.exe
You can actually log on to the remote machine and see in the GUI that it is happening. And yes, obviously you need to have the .msi which will be called to be present there in the remote machine so that the .exe can do its job locally in the remote session.

how do i make a service run a script outside of session 0

The UPS software I am using has functionality to run a script on the management PC (PC1) when it goes into battery mode. I have come up with a powershell script (ShutdownVM.ps1) that works fine on its own to Invoke-Commands on the VM server; shutting down VM's gracefully and turning off the host machine (SERVER). The first problem arose when the UPS software could not directly run a .ps1 file.
Simple enough, I thought I would make a simple .bat (shutdown.bat) file to run the .ps1 file on PC1 to shut everything off on SERVER. Running my .bat file from the desktop pc worked perfectly, but as the UPS software would run it as a service, my poor .bat file would run from Session 0.
Here is the code i used in Shutdown.bat:
#echo on
Powershell.exe -executionpolicy unrestricted -command C:\Windows\ShutdownVM.ps1
The interactive services manager would pop up and my computer would hang and finally the UPS software would turn it off and I'd be back to square one, with SERVER and its VM's still running. So I thought I would download and use PSExec to execute my shutdown.bat file.
I made another .bat file and called it PSExec.bat and below is the code in it:
#echo on
psexec.exe -accepteula \\PC1 -h -u user -p pass -i 2 C:\Windows\shutdown.bat
Finally! It tries to run! Upon checking the interactive services manager, it showed the PSExec was throwing the error "the system cannot find the file specified"
"The System Cannot Find The File Specified"
I have no idea what file it is even looking for, I have double, triple checked the path names in my scripts and still have no idea as to what it is doing. If anyone could shed any light (or let me know of an easier way to achieve what I am trying to do) that would be great. Thanks!
-F

PSEXEC, access denied errors

While I'm using PSEXEC.exe getting 'Access denied' error for remote systems.
Any idea about how to solve this?
Hi i am placing here a summary from many sources online for various solutions to "access is denied" :
most information can be found here (including requirements needed) - sysinternal help
as someone mentioned add this reg key, and then restart the computer :
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system
/v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
Read this knowledge base article to learn what this does and why it is
needed
Disable firewall (note - this will leave you with out any firewall
protection)
netsh advfirewall set allprofiles state off
if target user has a blank PW and you dont want to add one, run on target:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"LimitBlankPasswordUse"=dword:00000000
This didnt work for me, but i have read it did for others in a few places,
on target execute:
Start -> Run -> secpol.msc -> Local Policies -> Security Options -> Network Access: Sharing > and security model for local accounts > Classic – local users authenticate as themselves
if already in 'Classic':
move to "Guest only - .." run from elevated command prompt gpupdate \force
move back to 'Classic - .." again run from elevated command prompt gpupdate \force
This one solved my issue:
run on target from elevated command prompt "net use" look at ouput chart and for shares listed in remote column there (i only deleted the disconnected ones - you can try them all) run "net use [remote path from before list] /delete" then run 'net use \target\Admin$ /user:[user name]' enter prompt password request (if empty PW just press enter), viola should work.
I just solved an identical symptom, by creating the registry value HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system\LocalAccountTokenFilterPolicy and setting it to 1. More details are available here.
This helped in my case:
cmdkey.exe /add:<targetname> /user:<username> /pass:<password>
psexec.exe \\<targetname> <remote_command>
PsExec has whatever access rights its launcher has. It runs under regular Windows access control. This means whoever launched PsExec (be it either you, the scheduler, a service etc.) does not have sufficient rights on the target machine, or the target machine is not configured correctly. The first things to do are:
Make sure the launcher of PsExec is familiar to the target machine, either via the domain or by having the same user and password defined locally on both machines.
Use command line arguments to specify a user that is known to the target machine (-u user -p password)
If this did not solve your problem, make sure the target machine meets the minimum requirements, specified here.
You can try the command
net use \\computername\ipc$ /user:adminname password
to get admin permissions on remote PC before use psexec.
I had the same problem. And after a hard work, I found a easy and full solution:
I use runas to run the script in a admin account
I use the -s parameter in psExec to run in a system account
Inside the PsExec, I login again with a admin account
You can use & to run multiples commands
Remember to replace [USERNAME], [PASSWORD], [COMPUTERNAME], [COMMAND1] and [COMMAND2] with the real values
The code looks like this:
runas /user:[USERNAME] "psexec -e -h -s -u [USERNAME] -p [PASSWORD] \\[COMPUTERNAME] cmd /C [COMMAND1] & [COMMAND2]"
If you whant to debug your script in the another machine, run the following template:
runas /user:[USERNAME] "psexec -i -e -h -s -u [USERNAME] -p [PASSWORD] \\[COMPUTERNAME] cmd /C [COMMAND1] & [COMMAND2] & pause"
Try setting this key on the target (remote) machine, and restart the machine:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"LocalAccountTokenFilterPolicy"=dword:00000001
See: http://forum.sysinternals.com/topic10924.html and http://www.brandonmartinez.com/2013/04/24/resolve-access-is-denied-using-psexec-with-a-local-admin-account/
I just added "-с" parameter. It makes Psexec copy executable to remote machine. So it works without access errors.
I found Sophos kept placing psexec.exe into the Quarantine section. Once I authorized it, it ran fine.
I still use psexec, even on win 10. Replace the psexec.exe in the Windows 10's win32 folder with the older version to work -> I use version 2.11.0.0. The Windows 10 version I was using would only run .bat files as background/hidden process on the remote computer. Took a whole day to figure this out.
Adding the registry key from above to the remote computer helps as well:
reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
I found another reason PSEXEC (and other PS tools) fail - If something (...say, a virus or trojan) hides the Windows folder and/or its files, then PSEXEC will fail with an "Access is Denied" error, PSLIST will give the error "Processor performance object not found on " and you'll be left in the dark as to the reason.
You can RDP in; You can access the admin$ share; You can view the drive contents remotely, etc. etc., but there's no indication that file(s) or folder(s) being hidden is the reason.
I'll be posting this information on several pages that i was perusing yesterday while trying to determine the cause of this odd problem, so you might see this elsewhere verbatim - just thought I'd put the word out before anyone else pulled their hair out by the roots trying to understand why the performance counter has anything to do with PSEXEC running.
I had a case where AV was quarantining Psexec - had to disable On-access scanning
For anybody who may stumble upon this. There is a recent (Dec 2013) Security Update from Microsoft Windows on Windows 7 that is preventing remote execution.
See http://support.microsoft.com/kb/2893294/en-us
I uninstalled the Security Update by going to Control Panel\Programs\Programs and Features\Installed Updates
It worked right after that.
The following worked, but only after I upgraded PSEXEC to 2.1 from Microsoft.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"LocalAccountTokenFilterPolicy"=dword:00000001 See:
http://forum.sysinternals.com/topic10924.html
I had a slightly older version that didn't work. I used it to do some USMT work via Dell kace, worked a treat :)
On Windows Server 2012 R2 I had trouble to run from user account
psexec -u administrator -p password \\machinename -h -s -d -accepteula cmd.exe
But it works fine if you run without parameters -h -s. That's why I use this to solve my trouble:
psexec -accepteula -u administrator -p password \\machinename %PathToLocalUtils%\psexec.exe -h -s -d cmd.exe
I couldn't get access to remote machines unless I had UAC disabled.
That has to be done locally, either from control panel or running the following through cmd:
reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
While UAC is enabled, make sure you run cmd as administrator.
For a different command I decided to change the network from public to work.
After trying to use the psexec command again it worked again.
So to get psexec to work try to change your network type from public to work or home.
I tried a lot of way but I could not use psexec. It gives "Access denied". After I change the target user account type from Standard to Admin, I connected the machine via psexec.
I researched the reason why admin type account is required then I found this answer.
You can change target machine user account this way: Control Panel -> User Accounts -> Change Account Type. You must enter an admin account and password to change that account if you logged in standard account.
After that I logged in with this command: psexec \\remotepcname -u remoteusername -p remotepassword cmd
Tried all suggestions above, but still was unable to resolve the error. Finally once I made the below change, I could successfully run the PSexec command.
Turns out that when you have UAC enabled psexec does not work as supposed. We need to set HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA to 0 then psexec starts working as expected.