Navigation:  Scripting > System Scripts >

System Script Obsolete Functions

Previous pageReturn to chapter overviewNext page

The following system script functions are no longer included with Visual Build Pro.  Either convert your projects to use the listed replacement actions, or copy the script code below into your global script code.

 

Note: the Run Program action can be used in place of this script and provides a more robust way to remotely execute programs.

 

vbld_RemoteExecuteCmd(strServer, strCommand, strUserName, strPassword): Execute a command on a remote computer and return the exit code.

 

 

Note: the Service action can be used in place of these scripts and provides a simpler method for stopping and starting services.

 

vbld_ConnectServer(strServer, strUserName, strPassword): Connect to a remote server using WMI and return the server object.

 

vbld_GetService(strServer, strServiceName, strUserName, strPassword): Retrieve a WMI object reference to a remote service.

 

vbld_RemoteStartService(strServer, strServiceName, strUserName, strPassword): Start a remote service, returning True if started or False if already running.

 

vbld_RemoteStopService(strServer, strServiceName, strUserName, strPassword): Stop a remote service, returning True if stopped or False if already stopped.

 

 

Note: the COM+ Application and COM+ Component actions provide more functionality and should be used instead of the following scripts.

 

vbld_CreateApplication(strName, blnServer): Create/update a COM+ application, returning True if it did not exist or False if it already existed.

 

vbld_DeleteApplication(strName): Delete a COM+ application, returning True if it existed or False if it did not exist.

 

vbld_AddComponent(strApp, strDll): Install a component into a COM+ application, returning True if added or False if the application was not found.

 

vbld_ExportApplication(computer, appName, filename, options): Export a COM+ application or proxy to a file (see the script code for a description of the parameters).

 

vbld_InstallApplication(computer, filename, destDir, options, user, pwd, RSN): Install a COM+ application from a file (see the script code for a description of the parameters).

 

 

Note: the IIS and IIS Virtual Dir actions provides more functionality and should be used instead of the following scripts.

 

vbld_CreateVirtualDir(strPath, strName): Create/update an IIS virtual directory on the default web site to the specified path.

 

vbld_DeleteVirtualDir(strName): Delete an IIS virtual directory on the default web site.

 

 

vbld_CreateQueue(strName, strLabel): Create the specified MSMQ queue if it doesn't exist, returns True if did not exist and successfully created or False if it already exists.

 

vbld_DeleteQueue(strName): Delete the specified MSMQ queue if it exists, return True if deleted or False if it doesn't exist.

 

vbld_CreateShare(path, shareName): Create a network disk share of the given name to the path specified on the local computer.

 

vbld_DeleteShare(shareName): Delete the given network disk share from the local computer if it exists.

 

 

Obsolete Script Code

 

' Connect to a remote server using WMI and return the server object

Function vbld_ConnectServer(strServer, strUserName, strPassword)

 

   Dim objLocator

 

   'Create Locator object to connect to remote CIM object manager

   Set objLocator = CreateObject("WbemScripting.SWbemLocator")

 

   'Connect to the namespace which is either local or remote

   Set vbld_ConnectServer = objLocator.ConnectServer(strServer, "root\cimv2", strUserName, strPassword)

   vbld_ConnectServer.Security_.impersonationlevel = 3

 

End Function

 

' Retrieve a WMI object reference to a remote service

Function vbld_GetService(strServer, strServiceName, strUserName, strPassword)

 

   Dim objServer

 

       Set objServer = vbld_ConnectServer(strServer, strUserName, strPassword)

   Set vbld_GetService = objServer.Get("Win32_Service='" &  strServiceName & "'")

       

End Function

 

' start a remote service, returning True if started

' use "", "" for username and password if the current user has remote execute rights,

' otherwise specify a valid username/password for the remote server

Function vbld_RemoteStartService(strServer, strServiceName, strUserName, strPassword)

 

   Dim objService

 

       Set objService = vbld_GetService(strServer, strServiceName, strUserName, strPassword)

       vbld_RemoteStartService = (objService.StartService() = 0)

       

End Function

 

' stop a remote service, returning True if stopped

' use "", "" for username and password if the current user has remote execute rights,

' otherwise specify a valid username/password for the remote server

Function vbld_RemoteStopService(strServer, strServiceName, strUserName, strPassword)

 

   Dim objService

 

       Set objService = vbld_GetService(strServer, strServiceName, strUserName, strPassword)

       vbld_RemoteStopService = (objService.StopService() = 0)

       

End Function

 

' create/update a COM+ application, returning True

' if it did not exist

Function vbld_CreateApplication(strName, blnServer)

 

       Const COMAdminActivationInproc = 0

       Const COMAdminActivationLocal = 1

 

       Dim cllApps, objApp, i

       

       vbld_CreateApplication = False

       Set cllApps = vbld_ApplicationCollection

       i = vbld_FindCollectionIndex(cllApps, strName)

       If i >= 0 Then        ' update existing item if found

               Set objApp = cllApps.Item(i)

       Else                        ' add new app if not found

               Set objApp = cllApps.Add

               objApp.Value("Name") = strName

               vbld_CreateApplication = True

       End If

       

       If blnServer Then

               objApp.Value("Activation") = COMAdminActivationLocal

       Else

               objApp.Value("Activation") = COMAdminActivationInproc

       End If

       cllApps.SaveChanges

               

End Function

 

' delete a COM+ application, returning True

' if it existed

Function vbld_DeleteApplication(strName)

 

       Dim objCat, cllApps, objApp, i

       

       vbld_DeleteApplication = False

       

       Set objCat = CreateObject("COMAdmin.COMAdminCatalog")

       Set cllApps = objCat.GetCollection("Applications")

       

       i = vbld_FindCollectionIndex(cllApps, strName)

 

       If i >= 0 Then

               objCat.ShutDownApplication(strName)

               cllApps.Remove i

               cllApps.SaveChanges

               vbld_DeleteApplication = True

       End If

               

End Function

 

' add a component to a COM+ application, returning True

' if added or False if the application was not found

Function vbld_AddComponent(strApp, strDll)

 

       Dim objCat, cllApps, objApp, i

       

       vbld_AddComponent = False

       Set objCat = CreateObject("COMAdmin.COMAdminCatalog")

       Set cllApps = objCat.GetCollection("Applications")

       

       i = vbld_FindCollectionIndex(cllApps, strApp)

       

       If i >= 0 Then

               objCat.InstallComponent cllApps.Item(i).Key, strDll, "", ""

               vbld_AddComponent = True

       End If

       

End Function

 

' locate the given COM+ admin collection object by name and return

' its 0-based index or -1 if not found

Function vbld_FindCollectionIndex(cll, strName)

 

       Dim i, obj

       

       cll.Populate

       

       vbld_FindCollectionIndex = -1

       i = 0

       For Each obj In cll

               If LCase(obj.Name) = LCase(strName) Then

                       vbld_FindCollectionIndex = i

                       Exit For

               End If

               i = i + 1

       Next

       

End Function

 

' create an return the COM+ Applications collection

Function vbld_ApplicationCollection()

 

       Dim objCat, cllApps

       

       Set objCat = CreateObject("COMAdmin.COMAdminCatalog")

       Set cllApps = objCat.GetCollection("Applications")

       cllApps.Populate

       Set vbld_ApplicationCollection = cllApps

       

End Function

 

// Create the specified MSMQ queue if it doesn't exist,

// Returns True if did not exist and successfully created

function vbld_CreateQueue(strName, strLabel)

{

       var MQ_PEEK_ACCESS = 32;

       var MQ_DENY_NONE = 0;

       

       // create the queue info object

       var objQInfo = new ActiveXObject("MSMQ.MSMQQueueInfo");

       objQInfo.PathName = strName;

       

       var objQ = null;

       // will fail if it doesn't exist

       try

       {

               objQ = objQInfo.Open(MQ_PEEK_ACCESS, MQ_DENY_NONE);    // attempt to open the queue

       }

       catch (E)

       {}

       

       // if queue not found, create it

       if (objQ == null)

       {

               objQInfo.Label = strLabel;

               objQInfo.Create(false, false);    // non-transactional, non-world-readable

               return true;

       }

       return false;

}

 

// Delete the specified MSMQ queue if it exists, return True if deleted

function vbld_DeleteQueue(strName)

{

       var MQ_PEEK_ACCESS = 32;

       var MQ_DENY_NONE = 0;

 

       // attempt to create queue

       var objQInfo = new ActiveXObject("MSMQ.MSMQQueueInfo");

       objQInfo.PathName = strName;

       

       var objQ = null;

       // will fail if it doesn't exist

       try

       {

               objQ = objQInfo.Open(MQ_PEEK_ACCESS, MQ_DENY_NONE);    // attempt to open the queue

       }

       catch (E)

       {}

       

       // if queue not found, create it

       if (objQ != null)

       {

               objQInfo.Delete();

               return true;

       }

       return false;

}

 

' COMAdminApplicationExportOptions enum values

Const COMAdminExportNoUsers = 0

Const COMAdminExportUsers = 1

Const COMAdminExportApplicationProxy = 2

Const COMAdminExportForceOverwriteOfFiles = 4

Const COMAdminExportIn10Format = 16

 

' export a COM+ application or proxy to a file

' computer: computer to export from or "" for local computer

' appName: name of application to export

' filename: file to export the application to or "" to export to default directory

' options: sum of one or more values from COMAdminApplicationExportOptions (above)

Sub vbld_ExportApplication(computer, appName, filename, options)

 

       Dim objCat

       

       Set objCat = CreateObject("COMAdmin.COMAdminCatalog")

       objCat.Connect computer

       objCat.ExportApplication appName, filename, options

       

End Sub

 

' create/update an IIS virtual directory to the specified

' path

Sub vbld_CreateVirtualDir(strPath, strName)

 

       Dim objSvr, objDir

       

       Set objSvr = GetObject("IIS://LocalHost/w3svc/1/Root")

       

       On Error Resume Next    ' delete virtual directory if it exists

       objSvr.Delete "IIsWebVirtualDir", strName

       Err.Clear

       

       Set objDir = objSvr.Create("IIsWebVirtualDir", strName)

       

       ' set the permissions to read and call script

       objDir.AccessRead = True

       objDir.AccessScript = True

       ' set path to passed in value

       objDir.Put "Path", strPath

       objDir.SetInfo

       objDir.AppCreate True                ' True = InProc

       objSvr.SetInfo

 

End Sub

 

Sub vbld_DeleteVirtualDir(strName)

 

       Dim objSvr

       

       Set objSvr = GetObject("IIS://LocalHost/w3svc/1/Root")

       

       On Error Resume Next    ' delete virtual directory if it exists

       objSvr.Delete "IIsWebVirtualDir", strName

       Err.Clear

       

End Sub

 

' execute a command on a remote computer and return the result

' use "", "" for username and password if the current user has remote execute rights,

' otherwise specify a valid username/password for the remote server

Function vbld_RemoteExecuteCmd(strServer, strCommand, strUserName, strPassword)

 

   Dim objInstance, objServer

   Dim intProcessId, intStatus

 

   'Establish a connection with the server.

       Set objServer = vbld_ConnectServer(strServer, strUserName, strPassword)

 

       ' retrieve a process handle

   Set objInstance = objServer.Get("Win32_Process")

 

       ' run the command

   vbld_RemoteExecuteCmd = objInstance.Create(strCommand, Null, Null, intProcessId)

 

End Function

 

' create a disk share on the local computer with the given path and name

Sub vbld_CreateShare(sharePath, shareName)

 

   Dim objServer, objShare

 

   'Establish a connection with the server.

       Set objServer = vbld_ConnectServer("", "", "")

 

       ' retrieve a process handle

   Set objShare = objServer.Get("Win32_Share")

       objShare.Create sharePath, shareName, 0, Null, "", Null, Null

 

End Sub

 

' delete the given network disk share from the local computer

Sub vbld_DeleteShare(shareName)

 

   Dim objServer, objShare

 

   'Establish a connection with the server.

       Set objServer = vbld_ConnectServer("", "", "")

 

       ' retrieve a process handle

       Set objShare = Nothing

       On Error Resume Next

   Set objShare = objServer.Get("Win32_Share='" & shareName & "'")

   On Error Goto 0

   If Not objShare Is Nothing Then objShare.Delete()

 

End Sub