I am trying to run this code:
SendKeys "copy /b /y " & outputfile & " " & printerid & "{Enter}", 1.
It runs fine in Windows XP but in Windows 7 it gives an error.
I am trying to copy a string into cmd and execute it.
The "{Enter}" part is giving error.
Please help.
A quick test on Windows 7 gives me:
'sendkeys' is not recognized as an internal or external command,
operable program or batch file.
If that's the same error that you're getting, it means you don't have the program. Try copying it over from XP and see if that works.
If you've already copied it, it might not be in your PATH. Try this:
set PATH=%PATH%;C:\Path\to\SendKeys\
where C:\Path\to\SendKeys is the folder that contains SendKeys.exe.
Related
I have the following simple code that works and executes a powershell command in asp.net core website running on my cshtml.cs code behind page
using System.Management.Automation;
public void Execute()
{
using (var ps = PowerShell.Create())
{
ps.AddScript("Get-Date");
var results = ps.Invoke();
foreach (var result in results)
{
string test = result.ToString();
}
}
}
This works i get the current date reported as a string and results variable contains a count of 1.
"7/16/2020 4:38:27 PM"
If i then change it to another command say
ps.AddScript("Get-WmiObject");
or
ps.AddScript("Get-LocalGroupMember -group my_local_group_name");
Then i get no results, results comes back as count of 0 ?? The only thing i can determine is that Get-Date is a single string where as the other commands Get-WmiObject and Get-LocalGroupMember are multiple lines of text in the outputs when i execute them from a normal Powershell window.
my goal is to be able to execute the Get-LocalGroupMember command and get it's output. Is there something else i'm missing or not doing in terms of Powershell commands ? why is it some commands are working and producing output and others are not ?
UPDATE:
So i was getting error in the error stream of the ps object it states
{The 'Get-LocalGroupMember' command was found in the module 'Microsoft.PowerShell.LocalAccounts', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.LocalAccounts'.}
if i open a x86 Powershell window and run the Get-LocalGroupMember cmd it gives me error
Get-LocalGroupMember : The term 'Get-LocalGroupMember' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.
running the Get-LocalGroupMember cmd in a regular Powershell window (that is x64) the cmd runs perfect.
My project is set to x64 :( so am failing to understand why asp.net is using what seems to me a 32bit version of powershell. That's what i need i need to be able to execute my powershell cmds as x64 because Get-LocalGroupMember cmd is only available in Powershell x64 .
Please Help ? thanks
so i ended up having to do the following for some reason in order to get certian commands like Get-LocalGroupMember to work, other commands like Get-Date don't require the import, and even though on my system i had execution policy unrestricted, whenever i use c# in asp.net and checked errors on my ps object it was acting like it wasn't and would not let me run a script using AddScript. So i had to be administrator running visual studio and use set-executionpolicy like below, then be able to add the localaccounts module to be able to use Get-LocalGroupMember.. again if i open a x64 Powershell window on the system i can run Get-LocalGroupMember fine. seems c# is doing some weird things with the Powershell shell that it is creating and running in memory. Anyway hopefully this saves someone else time if they run into the same situation.
using (var ps = PowerShell.Create())
{
ps.AddScript("Set-ExecutionPolicy Unrestricted -force");
ps.AddScript("Import-Module Microsoft.PowerShell.LocalAccounts");
ps.AddScript("Get-LocalGroupMember -group your_local_group_name | Out-String");
var results = ps.Invoke();
foreach (var result in results)
{
string test = result.ToString();
TestText = test;
}
}
I tried to launch a program with Run & Runwait but the program don't appear
Run & Runwait command
Run('R:\Windows\Bureau\Hoop Bot\lib\scrcpy-win64\scrcpy-noconsole.exe')
Or
Run('#Scriptdir\lib\scrcpy-win64\scrcpy-noconsole.exe')
same with runwait
No error messages
Try setting the working dir for the program.
Run('R:\Windows\Bureau\Hoop Bot\lib\scrcpy-win64\scrcpy-noconsole.exe', 'R:\Windows\Bureau\Hoop Bot\lib\scrcpy-win64\')
And if you are using #ScriptDir it should go like this:
Run(#Scriptdir & '\lib\scrcpy-win64\scrcpy-noconsole.exe', 'R:\Windows\Bureau\Hoop Bot\lib\scrcpy-win64\')
It might be very silly what I'm asking, but I'm puzzled and stuck and can't find a solution. I have an executable file in two versions (linux and windows, so e.g. helloworld and helloworld.exe). From the R prompt, I want to call a command for making it run in both OS. So I call it using system and Sys.which but the local directory where they are, it's actually with space in the name so when I do
system(Sys.which("/home/laptop/dont try this at home/helloworld"))
I got
sh: 1: /home/laptop/dont: not found
I guess the error is in system as the shell has the real path with "\" before the space e.g.
/home/semolo/dont\ try\ this\ at\ home
but Sys.which works with "". do you have any idea?
Solution
I got the solution
system(gsub(" ", "\\\\ ", Sys.which("/home/laptop/dont try this at home/helloworld")))
I am trying to change the memory usage for R on a windows 7 machine.
I go to the desktop shortcut > properties and try to change the target from
"C:\Program Files\R\R-2.13.0\bin\i386\Rgui.exe" to
"C:\Program Files\R\R-2.13.0\bin\i386\Rgui.exe" --max-mem-size=500M
as per this post https://stat.ethz.ch/pipermail/r-help/2010-June/241154.html
But I get an error message "The name '"C:\Program Files\R\R-2.13.0\bin\i386\Rgui.exe" --max-mem-size=500M' specified in the target box is not valid, make sure the path and file name are valid."
Any suggestions on how to fix this?
I just tried it. It works fine on my machine. Maybe you entered the --max.. in the "execute-in"-field instead of the "target"-field. If this is not the problem try this: create a .bat file and enter yourpath\Rgui.exe --max-..., then create a shortcut to that .bat.
I set up TFS Deployer currenlty at work and have been tried to write a Powershell script for the deployment. I have been researched and read many posted questions and answers at StackoverFlow but I couldn't really making the script working yet.
So far, when I run the following PS on windows PowerShell ISE, it runs.
$envMsDeploy = $env:msdeploy
$DirMsDeploy = split-Path -Parent $envMsDeploy
# defined the current location to $DirMSDeploy = C:\Program Files\IIS\Microsoft Web Deploy V2
set-location $DirMsDeploy
$arg = #(
'-verb:sync';
'-source:contentPath=' + $buildDroppedLocation;
'-dest:contentPath=' + $destinationPath;
' -whatif > c:\temp\msdeploy.log'
)
$runMSDeploy = ($DirMsDeploy + "\Msdeploy.exe " + $arg)
$runMSDeploy | Out-file c:\temp\MsDeployTest.bat
I put the last sentence to confirm what gets saved $runMSDeploy. Now looks like $runMSDeploy saves what I want to put finally.
MSDeployTest.Bat contains C:\Program Files\IIS\Microsoft Web Deploy V2\Msdeploy.exe -verb:sync -source:contentPath=[[c:\source folder]] -dest:contentPath=[[Detination UNC path]] -whatif > c:\temp\msdeploy.log
This is where I'm stuck at right now. Because of the c:\Program files contains the empty folder, cmd doesn't run successfully rather giving me the error, "cmd.exe : 'C:\Program' is not recognized as an internal or external command"
If you have any suggestions or idea, please let me know.
thanks,
wanttogoshreddingeveryday
Here is a small example which start notepad.exe with a parametter
function F([string]$file)
{
notepad.exe $file
}
Clear-Host
F "c:\Temp\fic.txt"
JP
Try this gist. It should have everything you need to deploy via powershell https://gist.github.com/579086
It uses Psake, but it will work without it as well.