0
$CSharpSig = @'
[DllImport(“user32.dll”, EntryPoint = “SystemParametersInfo”)]

public static extern bool SystemParametersInfo(

                 uint uiAction,

                 uint uiParam,

                 uint pvParam,

                 uint fWinIni);

'@

$CursorRefresh = Add-Type -MemberDefinition $CSharpSig -Name WinAPICall -Namespace SystemParamInfo –PassThru
$CursorRefresh::SystemParametersInfo(0x0057,0,$null,0)
  • this script refreshs mouse cursor
  • if you run this script will not work !
  • but if you copy & Paste the codes in powershell
  • it will work !
  • I don't know how
  • What do you mean by run the script? Right click and "run with PowerShell"? – Santiago Squarzon Apr 10 '22 at 15:06
  • @SantiagoSquarzon yes – Abdullah Nabil Apr 10 '22 at 15:09
  • [1] if you load the code into the powershell.exe console [not the ISE], does it run there? ///// [2] if you add `pause` to the end of the script and then run in via right-click, does it show any errors? – Lee_Dailey Apr 10 '22 at 16:49
  • @Lee_Dailey script is crashing I tryed adding pause to the end. but it's crashing not showing any errors... Only Working by pasting codes in powershell interface (not ISE) – Abdullah Nabil Apr 10 '22 at 17:06
  • @AbdullahNabil - thank you for the added detail. PLEASE, add that info [& any other info you have] to your Question so that folks can easily find it. – Lee_Dailey Apr 10 '22 at 17:13
  • @Lee_Dailey basiclly I wanna make a script to do this commands and add it to my C# App. But I invoke all of that commands so I wanna make a script to do this... – Abdullah Nabil Apr 10 '22 at 19:48
  • @Lee_Dailey More Details ? I am changing the mouse scheme from registry [HKEY_CURRENT_USER\Control Panel\Cursors] and It will be applied when you restart your PC...But this commands working good to refresh the cursor ! tested many times. – Abdullah Nabil Apr 10 '22 at 19:51
  • @AbdullahNabil - you have provided details in the comments that are not in the Question. you will have better luck getting useful help if you add those details to the Question where they will be easy for people to find. ///// you are well beyond my skill level at this point, so all i can do to help you is provide advice on how to make a Question that is easy to understand AND complete. – Lee_Dailey Apr 10 '22 at 21:57

1 Answers1

0

Your issue is likely related to the character encoding, maybe due to the ps1 being saved without a BOM as VS likes to do, so your quotes are being misinterpreted.

To quickly test, copy/paste this line into your code instead and I bet it'll work fine.

[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
Mike Anthony
  • 429
  • 3
  • 9