I have a batch script which I am trying to open a file (powershell script on a network location). If I put the path as a local c:\test.ps1 it works fine but I cant seem to get it to work with the network file structure.
#echo off
(set/p adminuser=Enter Your Admin Account: )
runas /user:%userdomain%\%adminuser% "powershell "\\Server\share$\IT Support\Test\Test Share\test.ps1""
Any ideas?
Thanks.
Try this:
#echo off
(set/p adminuser=Enter Your Admin Account: )
runas /user:%userdomain%\%adminuser% "powershell -noexit & '\\Server\share$\IT Support\Test\Test Share\test.ps1'"
Related
I have this code which successfully kills my remote session and opens up Sketchup.
When I remote back in, Sketchup is open and available to use.
However, it only works if the user is an administrator.
Is it possible to change this script so it works for standard users?
Even if I had to put the local administrator credentials, I would be fine with that.
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
)
timeout /t 15
cd "C:\Program Files\SketchUp\SketchUp 2019"
sketchup.exe
I don't think the user has to be an administrator. You should be able to save the script in a .bat file and right click Run As Administrator. Doesn't that work?
One important point here is that SketchUp will also run with admin privileges and you wouldn't want any program running with elevated privileges unnecessarily. I would modify the script as such:
runas /trustlevel:0x20000 "C:\Program Files\SketchUp\SketchUp 2019\SketchUp.exe"
Edit: Here's a variation of the script which works for me under a regular user:
for /F "tokens=1,2,3,4,5" %%A in ('"query session | find "Active""') DO (tscon %%C /dest:console)
runas /trustlevel:0x20000 "C:\Program Files\SketchUp\SketchUp 2020\SketchUp.exe"
(You have to run the script as Admin)
I want to automate the export process which I take using expdp command in Oracle.
Following is the contents of batch file I have created to open PuTTY.
#echo off
"C:\Program Files\PuTTY\plink.exe" username#Ip_Addr -pw password -m Open_Putty.txt`
Following is the contents of Open_Putty.txt to execute different commands.
echo $ORACLE_SID;
Read oraenv;
But after opening Open_Putty.bat it disappears without showing any output.
Please help me with this. I want to set oraenv and run some more commands to take the backup.
It's unlikely that plink.exe disappears without showing any output. I assume you execute the batch file from a Windows Explorer or other GUI application, so the Plink console window disappears once Plink finishes (possibly with error) and you cannot read the output (error).
Make sure you execute plink.exe from a console window (typically a cmd.exe) or add pause command to the end of the batch.
Make sure Plink can find the script file (Open_Putty.txt). As you do not specify a path to the file, it has to be located in your current working directory. Safer is to use a full path to the script file:
"C:\Program Files\PuTTY\plink.exe" username#Ip_Addr -pw password -m "C:\path\Open_Putty.txt"
The backtick symbol at the end of the command should probably not be there.
The name "Open PuTTY" is bit confusing. You are not using PuTTY at all. And even if you refer to Plink by "PuTTY", your script file (Open_Putty.txt) is not opening PuTTY nor Plink. It's executing remote commands. So you should better name it export.txt or similar.
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 execute the command :- Powermt display dev = all in the command prompt of a remote computer. How do I do that ?
If you have PowerShell 2.0 or higher on both computers and can enable remoting on the remote computer by execute Enable-PSRemoting -Force, then from an elevated/admin PowerShell prompt you can run:
Invoke-Command -ComputerName remotepcname -ScriptBlock { <commands to execute remotely> }
This will execute the commands remotely and return the results to the local computer.
Here's another alternative to try where psexec and powershell fail. It's convoluted and hackish, but at least it's something else to try. :)
Firstly, share a folder on your own machine. Make sure an account with admin rights on the remote machine has write access to this share you create. Then execute the following:
wmic /node:remoteComputerAddr /user:adminOnRemoteComputer /password:adminPassword process call create "cmd.exe /c powermt display dev=all >>\\localComputerAddr\shareName\results.txt"
#type "c:\local\path\to\share\results.txt"
Unfortunately, wmic doesn't show you the output of the process it creates. That's why you enable a share on your local workstation, then redirect the output from the remote command to your share.
More info.
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]