VB.Net edit current users registry with elevated rights on Windows 7 - vb.net

So in IT environments we commonly lock down users profiles to prevent access to the registry, command, prompt, control panel,etc. This can easily be done via GPO. However, there are times when you need to make a quick change to the users profile when everything is locked down. Maybe it is to changes the video resolution or the wallpaper, or edit something under the restricted users HKEY_CURRENT_USER. So it is easy to reboot and login as an admin. Open their registry hive. and rename "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies" to Policies.disabled log them in and make the changes and refresh via gpupdate /force. But there should be a better way with impersonate user or Run As. But when you run RunAs as another user it runs it as the admin and you get the Admins HKCU.
How would you make it so you can run an app made in VB.NET that simply deletes "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies" so you can make those changes?

Related

Create a first-time logon script for new users

I am creating generalized images of a Windows 10 machine for my company and some of the software we use requires setting up for each user account. I have a script (.cmd) that can do all of the setup automatically. Is there a way to make the script run each time a new user logs on, but only the first time they log on?
Every guide I have found explains how to assign a script to a user, but I want to have the script automatically assigned and run the first time a new user logs in, without having to go back and assign the script to their account.
The company uses Active Directory to manage user accounts, so options that use AD are perfectly valid.
EDIT 1:
I found a guide for doing this in windows 7:
https://community.spiceworks.com/topic/886089-mdt-log-on-script-for-each-new-user-run-once
However, I cannot find the locscripts file or some equivalent on Windows 10.
It's possible to trigger a first-run script via the RunOnce registry key. The linked article describes mounting the default user registry hive and adding the RunOnce entry, so that any new profiles created in the future which are based on a copy of this registry will have this setting.

Failed to update database because the database is read only

This message appears every time I try to save the data to the DB.
Failed to update database because the database is read only
Note: This error comes only when the application is installed to C drive.
Front End: VB.NET
Back End:SQL Server
Is there any way to overcome this issue?
Or any way to restrict the user from installing the application on C drive?
I would check the file system privileges. I suppose you talk about an SQL server file database. You receive the message because the account trying to access your file database does not have the file system permissions to do so.
In order to confirm my suggestion, you allow everyone to access the specific directory with full permissions.
Then, you have to check what is the account trying to do the actual access. Probably it's a system account (user ASPNET or NETWORK SERVICE). You have to give the respective permissions to the specific account.
Then, restart IIS.
If you want to do this for a distributed stand-alone application. Then these permissions would have to change on each machine where the program would be installed. In order to avoid putting users in such a fuss, the setup program should do it. I am not an expert on setup programs, but even the simplest ones would give you the option to do it, after asking the system adminstrator's approval. I suppose you could build a custom action during the setup program which would change the specific folder's permissions, perhaps by using xcacls.exe.
Hope I helped!

Allow a TFS 210 User to Change Their Password

We work with a group of contractors that need access to our TFS 2010 server. I've got Active Directory running for our office, so every user has an AD account. Is there a way the TFS users can change their passwords through TFS? I've changed passwords before by having users RDP into computers and changing their account information there, but I'd rather not give the contractors RDP access (they just don't need it).
I tried selecting "user mush change password at next login", but TFS seems not to respond to that.
The only login vehicle the contractors use is TFS.
Thanks
That's correct, TFS doesn't provide a mechanism to change passwords. Your users will need to use some integration to Active Directory to change their password. It needn't necessarily be through an RDP session, as long as they can hit Active Directory's LDAP server, you should be able to allow this.
IIS ships with a tool called IISADMPWD that lets users change their password over the web.
In addition, you can build your own tool to change the password, like other people have done in PowerShell or perl. In addition, there appear to be various commercial tools to enable this.

A way to launch x applications as administrator automatically (Windows xp)

The problem is that in our clients their normal user doesn't have administrator privileges so when they have to install or update our programs they have to log again as administrator to install them and then log as their user which is cumbersome...
As some updates are automatic the "run as" solution isnt a valid one...
One good idea would be to mark a folder as "admin folder" so all the exes executed from that folder run as administrator (having configured the admin account previously)
or a configurable a list of executable names that must run as administrator (i say names because it could be different installers with different hash but with a generic exe name that identifies it as ours)
Does anyone know a program or windows configuration or c# code to achieve something like this?
It seems nobody knows how to do it or doesnt want to tell because its a security hole...ironically having this escalating privileges hole would be better than having the user as administrator for everithing :S... (Appart from not being a valid solution for our clients)

Vista + VB.NET - Access Denied while writing to HKEY_LOCAL_MACHINE

I want my program to be able to edit a values within a registry key that resides in 'HKEY_LOCAL_MACHINE'
My.Computer.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\XYZ", "MyValue", "MyData")
The above works fine in Windows XP, but throws an UnauthorizedAccessException in Vista.
You are running into Vista's UAC feature. It will not let you write to arbitrary places in the HKLM hive because you are not running with Administrative priviledges.
There are two ways to work around this issue
Run the program with Administrative priviledges (different than running a program as an account which has Administrative priviledges)
Choose another place, perhaps HKCU, to store the data
The second option is much better as it allows your application to run with non-Admin priviledges which you can't always assume your user has.
Here is a fairly detailed article on UAC. It's not 100% programming material but it gives a good explanation as to what exactly it is and you can hopefully relate that to your particular program: http://technet.microsoft.com/en-us/library/cc709691.aspx
Since changes to the Local Machine hive can have affect across the system you will find that changes to it are restricted to non-administrative users. If you try to run your same code on an XP machine a non-admin account you will get the same error. On Vista since the process is non-admin by default you are getting this error. Information on this is in the "Made for Windows 2000", "Made for Windows XP", and "Made for Windows Vista" certification guidelines.
Given that I've got little information on what your program is doing more information may be needed to give you specific guidance, so I will speak in the general case. You want your application to leave the local machine hive alone unless you need it. When your program is run in non-admin mode it you can either disable the functionality that requires access to these admin keys or you can request that the admin privs.
Vista has tighter restrictions around Adminstrator accounts. If you're not logged in as an Administrator account, you'll have to write to HKEY_CURRENT_USER as opposed to HKEY_LOCAL_MACHINE.
IMO, this makes more sense. Each user has their own settings/etc for their programs. If you want to make global settings for your program, you'll have to do it with an Administrator account.