VirtualBox

Ignore:
Timestamp:
Oct 13, 2020 10:30:53 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
140875
Message:

Main: bugref:9341: Testcase: Fixed some error in the script

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/autostart/tdAutostart1.py

    r86540 r86555  
    12271227        if fRc:
    12281228            sSecPolicyEditor = """
    1229 ' SetLogonAsAServiceRight.vbs
    1230 ' Sample VBScript to set or grant Logon As A Service Right.
    1231 ' Author: http://www.morgantechspace.com/
    1232 ' ------------------------------------------------------'
    1233 
    1234 Dim strUserName,ConfigFileName,OrgStr,RepStr,inputFile,strInputFile,outputFile,obj
    1235 strUserName = "%s"
    1236 Dim oShell
    1237 Set oShell = CreateObject ("WScript.Shell")
    1238 oShell.Run "secedit /export /cfg config.inf", 0, true
    1239 oShell.Run "secedit /import /cfg config.inf /db database.sdb", 0, true
    1240 
    1241 ConfigFileName = "config.inf"
    1242 OrgStr = "SeServiceLogonRight ="
    1243 RepStr = "SeServiceLogonRight = " & strUserName & ","
    1244 Set inputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile("config.inf", 1,1,-1)
    1245 strInputFile = inputFile.ReadAll
    1246 inputFile.Close
    1247 Set inputFile = Nothing
    1248 
    1249 Set outputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile("config.inf",2,1,-1)
    1250 outputFile.Write (Replace(strInputFile,OrgStr,RepStr))
    1251 outputFile.Close
    1252 Set outputFile = Nothing
    1253 
    1254 oShell.Run "secedit /configure /db database.sdb /cfg config.inf",0,true
    1255 set oShell= Nothing
    1256 
    1257 Set obj = CreateObject("Scripting.FileSystemObject")
    1258 obj.DeleteFile("config.inf")
    1259 obj.DeleteFile("database.sdb")
    1260 
    1261 WScript.Echo "Logon As A Service Right granted to user '"& strUserName &"'"
     1229$oUser = New-Object System.Security.Principal.NTAccount("%s")
     1230$oSID = $oUser.Translate([System.Security.Principal.SecurityIdentifier])
     1231$sExportFile = '.\cfg.inf'
     1232$sSecDb = '.\secedt.sdb'
     1233$sSecDb1 = '.\secedt.jfm'
     1234$sImportFile = '.\newcfg.inf'
     1235secedit /export /cfg $sExportFile
     1236$sCurrServiceLogonRight = Get-Content -Path $sExportFile |
     1237    Where-Object -FilterScript {$PSItem -match 'SeServiceLogonRight'}
     1238$asFileContent = @'
     1239[Unicode]
     1240Unicode=yes
     1241[System Access]
     1242[Event Audit]
     1243[Registry Values]
     1244[Version]
     1245signature="$CHICAGO$"
     1246Revision=1
     1247[Profile Description]
     1248Description=GrantLogOnAsAService security template
     1249[Privilege Rights]
     1250{0}*{1}
     1251'@ -f $(
     1252        if($sCurrServiceLogonRight){"$sCurrServiceLogonRight,"}
     1253        else{'SeServiceLogonRight = '}
     1254    ), $oSid.Value
     1255Set-Content -Path $sImportFile -Value $asFileContent
     1256secedit /import /db $sSecDb /cfg $sImportFile
     1257secedit /configure /db $sSecDb
     1258Remove-Item -Path $sExportFile
     1259Remove-Item -Path $sSecDb
     1260Remove-Item -Path $sImportFile
     1261Remove-Item -Path $sSecDb1
    12621262                           """ % (sUser,);
    1263             fRc = self.uploadString(oGuestSession, sSecPolicyEditor, 'C:\\Temp\\adjustsec.vbs');
    1264             if not fRc:
    1265                 reporter.error('Upload the adjustsec.vbs failed');
     1263            fRc = self.uploadString(oGuestSession, sSecPolicyEditor, 'C:\\Temp\\adjustsec.ps1');
     1264            if not fRc:
     1265                reporter.error('Upload the adjustsec.ps1 failed');
    12661266        if fRc:
    12671267            (fRc, _, _, _) = self.guestProcessExecute(oGuestSession,
    12681268                                                      'Setting the "Logon as service" policy to the user %s' % sUser,
    1269                                                       30 * 1000, 'C:\\Windows\\System32\\cscript.exe',
    1270                                                       ['cscript.exe', 'C:\\Temp\\adjustsec.vbs', '//Nologo'], False, True);
     1269                                                      60 * 1000, 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe',
     1270                                                      ['powershell.exe', '-file', 'C:\\Temp\\adjustsec.ps1', '-ExecutionPolicy',
     1271                                                       'Bypass' ], False, True);
    12711272            if not fRc:
    12721273                reporter.error('Setting the "Logon as service" policy to the user %s failed' % sUser);
    12731274        try:
    1274             oGuestSession.fsObjRemove('C:\\Temp\\adjustsec.vbs');
     1275            oGuestSession.fsObjRemove('C:\\Temp\\adjustsec.ps1');
    12751276        except:
    12761277            fRc = reporter.errorXcpt('Removing policy script failed');
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette