Per Dan and also build the script as a PS1 file and run until it works.
You do not need elevation to access AD if you are a Domain Admin.
You cannot close a form from the Load event. Place your code in the Activated event and it will work.
Why use a form?
script will not run without errors
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: script will not run without errors
I have full rights in our environment. I am a local Admin, Domain Admin and Enterprise Admin. So rights should not be an issue. The form does nothing except try to execute the code I provided. So what am I doing wrong? How come this does not run? Is there a way to create a .EXE that runs without any user interaction using this tool?
Thank you.
Thank you.
Re: script will not run without errors
Run this a a command prompt to test then create the event and use this scriptblock minus the "Invoke" line
Your use of the registry is odd and may be the source of many of you issues. YOU will need to debug this without a form.
- $formPostBuildADTasks_Activate = {
- $root = $dom.GetDirectoryEntry()
- $searcher = [adsisearcher]"cn=$env:computername"
- $result = $searcher.FindOne()
- $computer = [ADSI]$result.path
- $computer.Description = (get-ItemProperty hklm:\SOFTWARE\MGH).Description
- $computer.CommitChanges()
- $OU = (get-ItemProperty hklm:\SOFTWARE\Microsoft\MPSD\OSD).OSDDomainOUName
- $targetOU = [ADSI]"LDAP://OU"
- $computer.psbase.Moveto($targetOU)
- }
- $formPostBuildADTasks_Activate.Invoke()
- dan.potter
- Posts: 709
- Last visit: Wed Nov 14, 2018 11:39 am
Re: script will not run without errors
I'm just guessing registry as one of my pc's here prompts me for elevation, it's a computer policy and has nothing to do with domain permissions. start-run regedit..what's it do?mqh777 wrote:I have full rights in our environment. I am a local Admin, Domain Admin and Enterprise Admin. So rights should not be an issue. The form does nothing except try to execute the code I provided. So what am I doing wrong? How come this does not run? Is there a way to create a .EXE that runs without any user interaction using this tool?
Thank you.
Re: script will not run without errors
Registry keys are always readable.dan.potter wrote:I'm just guessing registry as one of my pc's here prompts me for elevation, it's a computer policy and has nothing to do with domain permissions. start-run regedit..what's it do?mqh777 wrote:I have full rights in our environment. I am a local Admin, Domain Admin and Enterprise Admin. So rights should not be an issue. The form does nothing except try to execute the code I provided. So what am I doing wrong? How come this does not run? Is there a way to create a .EXE that runs without any user interaction using this tool?
Thank you.
The code has many errors and issues which can create errors. Without the error message there is no way to help.
Re: script will not run without errors
I can open and update any part of the registry. I can create keys, edit keys, delete keys etc.... plus the script I am trying to run only reads registry keys (that do exist) and you don't need admin rights to read the registry.
Thanks.
Thanks.
Re: script will not run without errors
I repeat - you are trying to run a script in the form load event that tries to close the form. That will not work as expected. Run my copy of your script and be sure it works then place it in the form activated event.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: script will not run without errors
One thing that I also notice is that you try to use elevation AND RUNAS. That can not be done in one step. The way Microsoft implemented that prohibits that.
If you want to run a application as an elevated admin and you are a normal user you need to use RunAs first and THEN elevate.
But since the elevation is determined by a manifest BEFORE and exe is even loaded, Windows will do that backwards.
So in order to go from normal user to elevated admin you need a starter exe. The starter exe uses runas with the desired credentials as a member of the admin group.
Then you use elevation on the actual application to get to where you need to be.
Depending on your system settings there is an elevation prompt. That is a Windows functionality.
If you want to run a application as an elevated admin and you are a normal user you need to use RunAs first and THEN elevate.
But since the elevation is determined by a manifest BEFORE and exe is even loaded, Windows will do that backwards.
So in order to go from normal user to elevated admin you need a starter exe. The starter exe uses runas with the desired credentials as a member of the admin group.
Then you use elevation on the actual application to get to where you need to be.
Depending on your system settings there is an elevation prompt. That is a Windows functionality.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: script will not run without errors
But the script does not require elevation. It is simple ADSI calls that only require the user to be a domain admin. The problem is the code and how it is deployed.
The info about elevation is good when elevation is required.
The info about elevation is good when elevation is required.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: script will not run without errors
I mentioned it because the OP wrote:
"Under Build Settings I have chosen the following.
Embed a default manifest for elevation
Alternate Credentials" I've used a domain admin account and password. "
"Under Build Settings I have chosen the following.
Embed a default manifest for elevation
Alternate Credentials" I've used a domain admin account and password. "
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.