I'm attempting to create an autoclicker that can run in the background, or while other users use the computer and the account that the autoclicker is on is not logged off of (I'm using Windows 10)
I've tried running the script with administrative privileges. However, this still returns the same issue. I believe it may be an issue with Windows security and not powershell itself, however I do not know any other methods.
add-type -AssemblyName microsoft.VisualBasic
add-type -AssemblyName System.Windows.Forms
$wshell = New-Object -ComObject wscript.shell;
do {
[Microsoft.VisualBasic.Interaction]::AppActivate("Program")
[System.Windows.Forms.SendKeys]::SendWait("m");
start-sleep -Milliseconds 1050
} while ($true)
This is the output:
Exception calling "SendWait" with "1" argument(s): "Access is denied"
At C:\Users\me\Desktop\ASI.ps1:8 char:1
+ [System.Windows.Forms.SendKeys]::SendWait("m");
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : Win32Exception
Is there any method that can simulate key input, even if the desktop is locked?
You will not be able to complete what you are attempting to do natively.
You will be able to create a Virtual Machine that may be able to continue running while the computer is locked. That way you can run all your scripts and game inside the virtual machine, lock the physical machine and away you go.
Even running it as a scheduled task with "Run whether user is logged on or not" checked, it will not give you the desired results.
Related
I am running a task to execute a powershell script.
The script runs fine if I run it manually through powershell, or through the task scheduler with "Run only when user is logged on" is selected.
If I change it to "Run whether user is logged on or not" (even with highest privledges checked) I get the following error when I catch the exception from my powershell script that tries to open up internet explorer:
New-Object : Retrieving the COM class factory for component with CLSID {0002DF0
1-0000-0000-C000-000000000046} failed due to the following error: 80080005.
At D:\PSA\EYReserve\EY_reserve.ps1:14 char:18
+ $ie = New-Object <<<< -com internetexplorer.application;
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMExcept
ion
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Comman
ds.NewObjectCommand
I've tried steps provided in solutions for similar problems but they did not work. Namely modifying DCOM settings, adding "NETWORK SERVICE" with full permissions etc.
Anyone think of something I could have missed?
Thanks!
I have a scheduled task that runs a power shell console window with script (script is always runned from machine that has that scheduled task, so there is no remote task calling) that contains:
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait('~');
Problem is when I'm logged (remotely or locally) it runs smoothly (power shell console opens, procedure runs, key is pressed and procedure completes), but when I log off script is throwing exception in power shell console window:
Exception calling "SendWait" with "1" argument(s): "Access is denied"
At C:\Testing\Powershell\PageFeature.ps1:4 char:2
+ [System.Windows.Forms.SendKeys]::SendWait('~');
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : Win32Exception
I set task to run with my credentials even when I log off, and still getting messages in the console window.
What could be the root problem of this?
maybe just try:
$obj = new-object -ComObject WScript.Shell
$obj.SendKeys("~")
I'm writing some pretty simple scripts in Powershell 32-bit and they are working fine.
For instance, I want to open internet explorer to a webpage and start typing in keys. The following code works fine when I run it in powershell ISE.
Add-Type –AssemblyName System.Windows.Forms
$url = "http://WebAddress"
$ie = New-Object -com "InternetExplorer.Application"
$ie.Navigate($url)
sleep 30
[System.Windows.Forms.SendKeys]::SendWait("{2}{tab}{H}{E}{L}{L}{O}")
I have downloaded a Windows PowerShell plugin and have executed the same code through it and received the following errors:
Building on master in workspace C:\Program Files\Jenkins\workspace\Jenkins Test
[Jenkins Test] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\WINDOWS\TEMP\hudson257018662776252417.ps1'"
New-Object : Creating an instance of the COM component with CLSID {0002DF01-000
0-0000-C000-000000000046} from the IClassFactory failed due to the following er
ror: 80004005.
At C:\WINDOWS\TEMP\hudson257018662776252417.ps1:4 char:17
+ $ie = New-Object <<<< -com "InternetExplorer.Application"
+ CategoryInfo : ResourceUnavailable: (:) [New-Object], COMExcept
ion
+ FullyQualifiedErrorId : NoCOMClassIdentified,Microsoft.PowerShell.Comman
ds.NewObjectCommand
You cannot call a method on a null-valued expression.
At C:\WINDOWS\TEMP\hudson257018662776252417.ps1:5 char:13
+ $ie.Navigate <<<< ($url)
+ CategoryInfo : InvalidOperation: (Navigate:String) [], RuntimeE
xception
+ FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "SendWait" with "1" argument(s): "Access is denied"
At C:\WINDOWS\TEMP\hudson257018662776252417.ps1:9 char:42
+ [System.Windows.Forms.SendKeys]::SendWait <<<< ("{2}{tab}{H}{E}{L}{L}{O}")
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Is there a reason why my code will not work through Jenkins like it does in Powershell? I tried some simple echo scripts which worked fine, but any more complex and it throws an error.
You may need to set execution policy once: https://technet.microsoft.com/library/hh849812.aspx
Set-ExecutionPolicy Unrestricted
Run PowerShell as admin and run that command. There may be security concerns using Unrestricted. But if it works, read the link above and find the policy that works best in your context. Options are (copy/pasted from the link):
Restricted. Does not load configuration files or run scripts. Restricted is the default execution policy.
AllSigned. Requires that all scripts and configuration files be signed by a trusted publisher, including scripts that you write on
the local computer.
RemoteSigned. Requires that all scripts and configuration files downloaded from the Internet be signed by a trusted publisher.
Unrestricted. Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet,
you are prompted for permission before it runs.
Bypass. Nothing is blocked and there are no warnings or prompts.
Undefined. Removes the currently assigned execution policy from the current scope. This parameter will not remove an execution policy
that is set in a Group Policy scope.
I am attempting to automate a sharepoint 2013 deployment via remote powershell from the build server. Everything executes as expected except when having anything to do with some class in sharepoint dll's such as (Microsoft.SharePoint.Publishing, Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings)
If I run the same script locally under the same credentials it runs fine.
I have considered the below:
The user has full admin right on both machines
Disabled UAC on the remote server
Followed the required Remote Powershell steps in thig post (http://social.technet.microsoft.com/Forums/sharepoint/en-US/09b60466-5432-48c9-aedd-1af343e957de/user-cannot-be-found-when-using-invokecommand-newspsite-on-sharepoint)
I set powershell to run as admin by defualt via the registry (New-Item -Path "Registry::HKEY_CLASSES_ROOT\Microsoft.PowershellScript.1\Shell\runas\command" -Force -Name '' -Value '"c:\windows\system32\windowspowershell\v1.0\powershell.exe" -noexit "%1"')
Script Code:
#Set the radio buttons value
$settings = New-Object Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings (,$rootWeb)
$settings.GlobalNavigation.Source = [Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource]::PortalProvider
#Set the radio buttons value
$settings.CurrentNavigation.Source = [Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource]::PortalProvider
write-host "I am here.........................."
$settings.Update()
#Set the Publishing Web
$SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($rootWeb)
#Global Navigation Settings
$SPPubWeb.Navigation.InheritGlobal = $false
$SPPubWeb.Navigation.GlobalIncludePages = $false
The Remote Powershell output is as below:
I am here..........................
Exception calling "Update" with "0" argument(s): "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : UnauthorizedAccessException
+ PSComputerName : Contoso-DEVSP
Exception setting "GlobalIncludePages": "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
+ PSComputerName : Contoso-DEVSP
Many thanks in advance
You need to check CredSSP authentication. Remote PowerShell execution with SharePoint fails as the second hop translates the credentials to system credentials. If the task involves querying or updating DB server, it will fail as SYSTEM account will not have access the remote PowerShell on SQL Server. You need to enable CredSSP.
Check this blog post I wrote a while ago. This is not specific to SharePoint but it should apply to your scenario as well.
http://www.ravichaganti.com/blog/?p=1230
I have this script which connects to a bunch of servers and gets service status, errors from the Application and System logs and disk space. It runs fine as a scheduled task on Windows XP but has some weird problem on Windows 2008. I am using a function to import the credentials from a separate file where they are stored in encrypted form:
function Import-credential($path) {
$cred = Import-Clixml $path
$cred.password = $cred.Password | ConvertTo-SecureString
New-Object system.Management.Automation.PSCredential(
$cred.username, $cred.password)
}
This works fine when I run it manually and when it runs as a scheduled task on Windows XP but fails on Windows 2008 with the following error:
New-Object : Exception calling ".ctor" with "2" argument(s): "Cannot process ar
gument because the value of argument "password" is null. Change the value of ar
gument "password" to a non-null value."
At F:\Tools\MCHS Server Report\monitor.ps1:9 char:15
+ New-Object <<<< system.Management.Automation.PSCredential(
+ CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvoca
tionException
+ FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.Power
Shell.Commands.NewObjectCommand
This is line 9:
New-Object system.Management.Automation.PSCredential(
In the task scheduler I have the full path to powershell.exe in Program/Script and -command & "F:\Tools\MCHS Server Report\monitor.ps1" in Add Arguments.
Any ideas?
EDIT: I tried changing the account it runs under to my own (I was using a local account specifically created for the scheduled tasks) and it worked alright. I have 0 ideas as to why it won't work with the other user considering we're both Administrators and seem to have the same privs...
ConvertTo-SecureString/ConvertFrom-SecureString by default use an encryption key that is bound to the user and computer that the string was originally encrypted on. If you log in as the service account and save the credential it should be able to decrypt it when it is running as a service.