Re: Newbie help needed with scripting permissions



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


.



Relevant Pages

  • Re: scripting patch installation
    ... what i want is for it to just install the ... > patch if that registry value is non existant. ... If you want a script that also can handle different OS version and Service pack ... Below is an updated version of your script that uses the function RegRead to ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Newbie help needed with scripting permissions
    ... >One option is to use a VBScript StartUp script configured in Group Policy. ... and another to silently uninstall. ... >You could code the VBScript to first uninstall, ... you could save the month/year in the registry ...
    (microsoft.public.windows.server.scripting)
  • Re: Microsoft Warns of New Windows Flaw (March 19, 2003 )
    ... In WINDOWS SETUP in ADD/REMOVE PROGRAMS of Control Panel ... Uninstall Outlook Express, ... Java, Javascript, ActiveX and all the other script runner toys Billy ... Install WebWasher the spammers are terrified of free from ...
    (comp.security.misc)
  • Re: Microsoft Warns of New Windows Flaw (March 19, 2003 )
    ... In WINDOWS SETUP in ADD/REMOVE PROGRAMS of Control Panel ... Uninstall Outlook Express, ... Java, Javascript, ActiveX and all the other script runner toys Billy ... Install WebWasher the spammers are terrified of free from ...
    (comp.security.firewalls)
  • Re: SMS Installer cannot create an NT Service
    ... If you want to post the script I could look over it real quick and see if I ... You can set permissions on registry keys and hives through something like ... I did a repackage of this install using SMS ...
    (microsoft.public.sms.installer)