Re: Newbie help needed with scripting permissions
- From: "Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 5 Jan 2006 20:59:36 -0600
Fran wrote:
>I am new to VBS scripting. I have a client that needs to uninstall and
> reinstall an app every 30 days (don't ask...it's silly but it's what
> it is...) The client runs the computer under Domain User rights but
> the app needs access to a new folder it creates for itself on install
> (off the root of C:).
>
> So far, every month I open Control Panes, run Add/Remove using RunAs
> and uninstall the app. Then I have to reinstall the app (again using
> RunAs). After the app installs I then have to go to the C:NewApp
> folder and grant the user (Bob) modify permissions.
>
> When the app is uninstalled it removes the folder, that's why I have
> to redo this. I can automate the install process using RunAs in a
> batch file using CPAU (found on the internet) to encrypt the whole
> execution string (including password for a local admin account I
> created on this windows XP machine) but I don't know how I can do the
> permissions thing.
>
> After playing with VBS I believe there is enough power in there to run
> a script under local admin rights (maybe again using RunAs in a CPAU
> file?) but I have no clue how to do that.
>
Hi,
One option is to use a VBScript StartUp script configured in Group Policy.
StartUp scripts run with System privileges on the machine (same as
administrator). This assumes you have an executable that will silently
install, and another to silently uninstall. For example, a script to run
setup.exe with a parameter.
================
Option Explicit
Dim objShell, strCommand
Set objShell = CreateObject("Wscript.Shell")
strCommand = "%COMSPEC% /c Setup.exe -q"
intReturn = objShell.Run(strCommand, 0, True)
If (intReturn <> 0) then
' Setup failed.
End If
=================
The "0" in the Run method means to run hidden, and the True means to wait
for the program to finish before continuing.
You could code the VBScript to first uninstall, then install. You would
either enable the script once per month, or code something to have it run
once per month. For example, you could save the month/year in the registry
and have the script first check if the value in the local registry matches
the current month/year. If it does exit, otherwise uninstall, install, and
save the current month/year in the registry. A quick try at this would be:
===========================
Option Explicit
Dim objShell, strLastMonth, strThisMonth
' Retrieve Month/Year.
strThisMonth = Month(Now) & "/" & Year(Now)
Set objShell = CreateObject("Wscript.Shell")
' Retrieve month/year when this program last ran
' from the local registry.
On Error Resume Next
strLastMonth = objShell.RegRead("HKLM\Software\MyApp\Month")
If (Err.Number <> 0) Then
' The registry entry does not exist. Program never ran.
On Error GoTo 0
strLastMonth = ""
End If
On Error GoTo 0
If (strThisMonth = strLastMonth) Then
' Program already run this month so exit.
Wscript.Quit
End If
' Run uninstall program, wait, then run install program,
' similar to the snippet above.
' Save this month/year in registry.
objShell.RegWrite "HKLM\Software\MyApp\Month", strThisMonth
=======================================
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
.
- Follow-Ups:
- References:
- Prev by Date: Re: [MSH] <INPUT REQUESTED> Standard Verbs
- Next by Date: Re: Disable multiple computers logon
- Previous by thread: Newbie help needed with scripting permissions
- Next by thread: Re: Newbie help needed with scripting permissions
- Index(es):
Relevant Pages
|