Start batch through powershell without getting asked for administration rights - powershell

Is there a way to start a batch file with administration rights using Powershell? (I mean in a way that you won't have to click a yes start thing that pops up.)

If you
Disable UAC, or
have PowerShell already running with administrative privileges
The entire point of UAC and selective elevation is that it's a noticeable action.

you can set variable __COMPAT_LAYER=RunAsInvoker (though it will give you no admin permissions for some operations pop-up will not appear) or disable UAC

Related

Bat-file prohibit user input

I'm making a .bat-file run a powershell script, and I need to make sure the script does not ask for user input og anything as such may halt the clean running of the script.
So my question's are:
How do I set input of all kind disabled?
Is there anything else I need to think about when running a powershell script remotely on a computer where the computers users shall have no interaction with the script what so ever?
Thanks
Have a good weekend! :)
Use the -NonInteractive switch on PowerShell.exe. From the usage info:
-NonInteractive
Does not present an interactive prompt to the user.
I've not used it myself so I can't say how well it works. YMMV. :-)
You can disable input with the NonInteractive switch but commands that prompts the user will still wait for input.
There are many cmdlets that prompts for confirmation. You can try and set the $ConfirmPreference preference variable to 'none' to override prompting.
Other than that, the best thing would be to test your script before you use it in production. That's the best way to find out if your scripts can hang waiting for someone to respond.

Script to simulate Guest Mode

This is my first question here so, sorry if I break any rule I didn't know yet or don't follow any good practice. But, let's go.
I have a Windows 7 laptop and, usually, colleagues ask me to use it to google something, use Word or something else. I'd like to have a secure area for guests (like what Guest Mode was going to be, until it was removed from Windows 7 final version), enabling guests to browse, do what they want and, during the logoff, undo any changes made and wipe guest user data. As I'm former linux user, my first thought was something like a script called by Cron or on the Init appropriate level.
After googling a bit, I've found information about logon and logoff scripts. I know nearly nothing about scripting in MS platform. Do you think that this approach would be a good solution to my problem? If it is, in which language would I have to write this script? If possible, please provide some simple examples. After getting the basic concepts I can handle the rest.
Thanks a lot!
I am hoping this can answer your question, even though it will not include batch scripting.
Here is a guest account on windows 7:
(source: sevenforums.com)
Open the Control Panel (All Items View).
Click on the User Accounts icon.
Click on the Manage another account link. (See screenshot below)
(source: sevenforums.com)
If prompted by UAC, then click on Yes.
Click on the listed Guest account. (See screenshot below)
(source: sevenforums.com)
Click on the Turn On button. (See screenshot below)
(source: sevenforums.com)
The guest account is now turned on. Close the User Accounts window. (See screenshot below)
(source: sevenforums.com)
A script to delete things is:
rd c:\directory1\ /s /q
md c:\directory1
rd c:\directory2\ /s /q
md c:\directory2
ect.
so...
rd "Insert filepath you want removed here" /s /q
md "Same filepath"
For each directory your want removed, you must have a rd and md.
Save this into your "startup" folder so it will run each time you log-in.

Handling UAC prompts when doing UIAutomation

Is there a way to access the UAC prompts via UIAutomation (I'm writing a test for an installation process).
From http://msdn.microsoft.com/en-us/library/ms742884.aspx it looks like there is a way to set this up.
So the question is how to make this automatically?
My current UIAutomation setup is made of the amazing White API (white.codeplex.com) with a bunch of extension methods from the O2 Platform
For security reasons, this is guaranteed to be impossible.
The whole point of UAC is that programs cannot automatically click Allow.
Not exactly the answer you'd have liked but a workaround based on SLaks's answer (Thanks #SLaks for answer) i.e. for security reasons Windows wouldn't allow automated clicks on the 'yes'. In that case if bypassing is the only option we could have same effect as elevated prompt and clicked yes by setting "UAC: Behaviour of elevation prompt for administrators in Admin Approval Mode" to 'Elevate without prompting' in security policy. I tried this in my automated tests and they are giving me same effect as clicking 'yes' on that prompt if it was prompted. Of course it isn't prompting since I've changed that option.

Is there a way to automatically log onto a Windows XP machine at specific time?

How to set a specific logon time for a specific user on Windows XP?
For example, the computer is an "always on machine" and most of the time no one is logged on. I want to set a time for my user to log on, without someone actually having to be in front of the machine. I've tried a workaround with the built-in auto logon function (control userpassword2), but I still need a secure system as I'm not the only user, and would still want a password even if I was the only user.
I have searched for third party software, but to no avail. I've a good knowledge of batch and Python scripting and a little of Java, so any pointers with any of those would help.
How can it be "secure" if it logs you on without you being there? Surely it would be better for it to wait for you to type in a password (i.e. the login prompt)?
If you want a fast "startup" time, then you can lock the workstation (ctrl+alt+del to open the Task Manager and then click 'Lock'. This shows a dialog just like the login prompt, but when you enter your password you instantly continue your existing session). Or if you want to be more eco friendly, put your PC into Sleep mode, which most PCs will return from (again with an optional password prompt) in less than 5 seconds.
One way I just thought of: Run a Vnc Server, and hack into an open source viewer program. Then you can rig it with some code to pass keyboard commands back into the computer, maybe implement some screen scraping to make sure it only does it when appropriate.
But seriously, there has to be a better way. Why are you trying to do this?

Strange behavior by the BDE Administrator

Logged into my Windows XP SP2 computer using my normal user account (which has Local Admin privileges), when I start the BDE Administrator -- either from the Control Panel or from the BDEADMIN.EXE directly -- I never get the GUI. It shows up on my task bar, and shows up in the Task Manager, but the GUI never appears. I can close the program by right-clicking on the task bar and choosing close. (note that "never" means not within 5 minutes of launching the program)
If I log into the same exact computer using a different user account (which also has Local Admin privileges), when I start the BDE Administrator, it loads the GUI within a couple seconds.
I used to be able to use the BDE Administrator while logged in under my normal user account, so it's not like this has always been a problem.
While this issue may not be directly programming related, it does make developing and testing a pain when I have to log off and back on a couple of times just to make changes to my BDE configuration.
I am totally stumped. Any idea what might be causing this odd behavior?
One idea is that you may have had two screens running on this box and dragged the window off screen.
Just search for the registry keys that control where the window opens up and delete them. Alternatively, you should be able to right click on the program in the task bar and select Move. Then use your arrow keys to bring it back.
Regardless, I'm voting to close.