Passing arguments to VBScript Program Object - Without WScript.Arguments?

I am trying to create a program object with a VBScript that will change the name of a PDF created by a scheduled report. I need to be able to tack on the string "OH_2010_Qtr_1" (or whatever state - OH is used as an example) before the file extension - the VBScript creates that string based on the date the report is run. I want to be able to pass parameters to this script but when I try to do so I get the error "Variable is undefined 'WScript'" when trying to run the program object. I tried creating a batch file that would pass in the parameters and I get a generic error.
How can I pass arguments to my VBScript? The arguments are necessary because this is for multiple instances of the same report, run for different states.

For VBScript Program Objects, some injected objects:
For Each arg in Script.Args
    ' Do something interesting with String arg here
    Script.Writeln(arg) ' Output to stdout
Next
and
' Get InfoStore
Set infoStore = Session.Service("", "InfoStore")
Sincerely,
Ted Ueda

Similar Messages

  • VBScript as program object - alternative to WScript.Arguments?

    I am trying to create a program object with a VBScript that will change the name of a PDF created by a scheduled report.  I need to be able to tack on the string "OH_2010_Qtr_1" (or whatever state - OH is used as an example) before the file extension - the VBScript creates that string based on the date the report is run.  I want to be able to pass parameters to this script but when I try to do so I get the error "Variable is undefined 'WScript'" when trying to run the program object.  I tried creating a batch file that would pass in the parameters and I get a generic error. 
    How can I pass arguments to my VBScript?  The arguments are necessary because this is for multiple instances of the same report, run for different states.
    Edited by: marykDBA on Mar 24, 2010 10:17 PM

    please post this question in the developer forum below
    .NET SDK Application Development

  • Is it possible to find an instance of an object without it being passed to

    Hi all,
    I have a parser class "MessageParser" which i pass a message which is of type "String" to it for it to be parsed. The parsing method signature for the class is
    public void parse(String message);
    I need to pass an instance of "Properties" to it but i dont want to change the signature of the method to add a new argument to it. I have been struggling with this for the last couple of days and have tried a couple of options - see http://stackoverflow.com/questions/5134462/sending-in-an-object-of-type-object-instead-of-string-polymorphism
    The class that calls the parsing method "ParserManager" knows of the properties object. Is there a way for the MessageParser to find the properties object without it being passed to it?
    Thanks
    ps - also posted in http://stackoverflow.com/questions/5140795/is-it-possible-to-find-an-instance-of-an-object-without-it-being-passed-to-the-me

    ziggy wrote:
    I need to pass an instance of "Properties" to it but i dont want to change the signature of the method to add a new argument to it. I have been struggling with this for the last couple of days and have tried a couple of options - see http://stackoverflow.com/questions/5134462/sending-in-an-object-of-type-object-instead-of-string-polymorphism
    The class that calls the parsing method "ParserManager" knows of the properties object. Is there a way for the MessageParser to find the properties object without it being passed to it?I completely agree with Kayaman if you can get away with only the passing the Properties once (as he suggests, at construction time).
    If you can't (ie, you must pass the Properties with each message), then I suspect you have a new type of Parser, and your design will have to reflect that.
    One possibility would be to extend Parser with a PropertiesParser interface that defines a new parse() method and either update the current ParserManager to "understand" the difference, or create a new one.
    The problem with the first option is that the manager then becomes a dispatcher, which kind of goes against the grain of OO programming (what if you need to add a third type of parser, or a fourth?).
    Another possibility (probably better) would be to create a variant of your MessageObject class that includes Properties, and a variant of your MessageCParser that knows how to deal with such an object.
    There are many ways to go, and only you probably know which is best.
    That said, if you can get away with passing the Properties once, definitely follow Kayaman's advice.
    Winston

  • Accessing object without passing it?

    Im making a complicated program with a swing UI. Every component is its own file and is created in the frame classes. There is a controller class that controls the application. I want to be able to access and modify variables in the controller class in each component. Is there a way to do this without passing any variables? Thanks!!

    There are a number of ways you could do it (you could make all controller methods and variables static... But please don't do that... or you could monkey around with ThreadLocals... Again, really think hard before going there).
    But if you're going to have a single controller I'd recommend enforcing that through a singleton pattern. Expose the controller instance through your Controller.getInstance() and call the methods you need on that.
    It's probably the cleanest way to do it and is less of a dependency nightmare than passing the controller or component objects through to each object that needs a connection to it.

  • Passing parameters to Java JT400 object

    I need to pass a byte array as my input and an int as the output length for the Class ProgramCall.
    My error is   
    parameterList[0] (null): Parameter value is not valid.
    My thoughts are
    I think (but I'm not completely sure) I'm having trouble because I'm passing a Coldfusion Array where a Java Array is needed to pass the arguments.
    Coldfusion arrays start at index 1 and Java Arrays start at index 0.
    (1) Am I correct in what I believe is causing my error?
    (2) How can I convert the Coldfusion Array to a Java Array?
    Here is the documentation for Java JT400 object Class ProgramCall
    http://publib.boulder.ibm.com/iseries/v5r1/ic2924/info/rzahh/javadoc/com/ibm/as400/access/ ProgramCall.html
    Here is my code
    <!--- I am the system object --->
    <cfobject
            action="create"
            type="java"
            class="com.ibm.as400.access.AS400"
            name="mysystem">
    <!--- I am the program call object ---> 
    <cfobject
            action="create"
            type="java"
            class="com.ibm.as400.access.ProgramCall"
            name="myprogram">
    <!--- I am the program parameter object ---> 
    <cfobject
            action="create"
            type="java"
            class="com.ibm.as400.access.ProgramParameter"
            name="myparameter">
    <!--- I am the as400 text object ---> 
    <cfobject
            action="create"
            type="java"
            class="com.ibm.as400.access.AS400Text"
            name="mytext">
    <!--- Initialize our system object --->
    <cfset mysystem.init(AS400system,Trim(UCase(loginname)),Left(Trim(loginpass),10)) />
    <!--- Execute our AS400 username validation --->
    <cfset mysystem.ValidateSignon() />
    <!--- Initialize our as400 text object and convert string to a byte array --->
    <cfset mytext.init(5) />
    <cfset nametext = mytext.toBytes("hello") />
    <!--- Initalize our program parameter object --->
    <cfset myparameter.init(2) />
    <!--- Set input data and output data length using the Class methods of ProgramParameter --->
    <cfset myparameter.setInputData(nametext) />
    <cfset myparameter.setOutputDataLength(20) />
    <!--- Set parameters to a Coldfusion Array --->
    <cfset parameterlist = ArrayNew(1) />
    <cfset parameterlist[1] = myparameter.getInputData() />
    <cfset parameterlist[2] = myparameter.getOutputDataLength() />
    <!--- Initalize our program object and run our program --->
    <cfset myprogram.init(iseries,ProgramtoRun, parameterlist) />
    <cfset myprogram.run() />

    reggiejackson44 wrote:
    I need to pass a byte array as my input and an int as the output length for the Class ProgramCall.
    My error is   
    parameterList[0] (null): Parameter value is not valid.
    My thoughts are
    I think (but I'm not completely sure) I'm having trouble because I'm passing a Coldfusion Array where a Java Array is needed to pass the arguments.
    Coldfusion arrays start at index 1 and Java Arrays start at index 0.
    (1) Am I correct in what I believe is causing my error?
    (2) How can I convert the Coldfusion Array to a Java Array?
    (1) Yes.
    (2) A ColdFusion array and a Java array are 2 entirely different things. You have yourself identified one difference, the starting index. In fact, the following line of code will tell you that a ColdFusion array is essentially a Java vector.
    <cfoutput>#arrayNew(1).getClass().getSuperClass().getname()#</cfoutput>
    In my opinion, your question should read the other way around: how to convert a Java array into ColdFusion, not necessarily into a ColdFusion array.
    Here are some tips and tricks:
    http://blogs.adobe.com/cantrell/archives/2004/01/byte_arrays_and_1.html
    http://www.bennadel.com/blog/1030-Building-Java-Arrays-In-ColdFusion-Using-Reflection.htm

  • VBScript which is called with Arguments from Command Line

    Hi There.
    I have been tasked to create a VBScript which needs to accomplish the following:
    It needs to be called from a command line using 4 different arguments, the arguments in order as follows:
    -          Drive letter including colon
    Warning threshold in percentage
    Warning threshold in GB remaining
    Recipient email address
    I need to be able to set up a scheduled task, to run this script, but at the same time I need to be able to specify multiple drive letters as separate steps but on a single task.  The script needs to automatically run every 4 hours, starting at 06:00AM
    in the morning and running no later than 22:00 at night.
    The end results, need to then be e-mailed to the Recipient which is specified in Argument (3).
    Following is my current script, it is not complete as I am currently pulling my hair out due to having a lack of knowledge of VBScripting....  :(  The current script also loops every 10 minutes or so, and uses the incorrect way of sending the results,
    we would like to use POSTIE.EXE to send the mail as we would want to eliminate web traffic (Microsoft Schema's) in this script.
    =====================================================================================
    Const emailFrom = "default_from_email_address_comes_here"      'From email address 
    Const ExchangeServer = "ExchangeServerName_comes_here"      'Enter your Exchange server name here (FQDN)
    Const WaitTimeInMinutes = 10                   'Wait time between loops. This is will be in minutes
    Dim WshShell, objArgs, strIP, objWMIService, LogicalVolumes, strDriveLetter
    Dim objItem, strDriveName, IntCapacity, IntFree, DiskFreePct
    Dim strIgnoreFlag
    Dim strMessage, IntStatistic
    on error resume next
      strDriveLetter         = WScript.Arguments(0)   'This is the drive letter which you want to monitor on the localhost
      DiskFreePct            = WScript.Arguments(1)   'This is the threshold percentage of free space
      ThresholdGB           = WScript.Arguments(2)
      Recipient                = WScript.Arguments(3)   'This is where the e-mail needs to be sent to
    If Err.Number <> 0 Then
      msgbox "You did not supply the arguments after calling the VBS file:" & vbcrlf & "<Drive Letter, eg:  C:>"& vbcrlf & "<Warning Threshold in Percentage> "& vbcrlf &"<Warning
    Threshold in GB Remaining> "& vbcrlf &"<Recipient E-Mail Address>"
      WScript.Quit
    End If  
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    WScript.Echo WshNetwork.ComputerName
    arrServerList = array(WshNetwork.ComputerName)    'This is where your localhost will be used as the query
    Do until i = 2
        'Clear the message variable
        strMessage = ""
        'Poll the array of servers
        PollServers(WshNetwork.ComputerName)
        'Email if there is a message
        if strMessage <> "" then
            EmailAlert(strMessage)
        end if
        'The script will loop for now just for testing. Uncomment the line that follows the loop logic to cancel the loop.
        WScript.Sleep(WaitTimeInMinutes*60000)
            'i = i + 1
    Loop
    Sub PollServers(arrServers)
        on error resume next
        for each Server in arrServers
            set objSvc = GetObject("winmgmts:{impersonationLevel=impersonate}//" & Server & "/root/cimv2")
            set objRet = objSvc.InstancesOf("win32_LogicalDisk")
            for each item in objRet
                if item.DriveType = 7 then
                    end if
                    if item.FreeSpace/item.size <= AlertHigh then
                        strMessage = strMessage & UCase(strPC) & "  Drive '" & item.caption & "' is low on disk space!  There are " & FormatNumber((item.FreeSpace/1024000),0)
    & " MB free" & vbCRLF
                    end if
            next
        next
        set objSvc = Nothing
        set objRet = Nothing
    End Sub
    Sub EmailAlert(Message)
        on error resume next
        Set objMessage = CreateObject("CDO.Message")
        with objMessage
            .From = emailFrom
            .To = Recipient
            .Subject = "Server " & WshNetwork.ComputerName & " is low on Disk Space" 
            .TextBody = Message
            .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ExchangeServer
            .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Configuration.Fields.Update
            .Send
        end with
        Set objMessage = Nothing
    End Sub

    I've managed to get the script fully working as required.
    ================================================================
    Const emailFrom = "your_email_here"      'From email address
    Const ExchangeServer = "exchange_server_name"      'Enter your Exchange server name here (FQDN)
    Const WaitTimeInMinutes = 240                   'Wait time between loops. This is will be in minutes
    Dim WshShell, objArgs, strIP, objWMIService, LogicalVolumes, strDriveLetter
    Dim objItem, strDriveName, IntCapacity, IntFree, DiskFreePct
    Dim strIgnoreFlag
    Dim strMessage, IntStatistic
    Dim DrivePercentage
    Dim DriveSpaceRem
    Dim mbFreeSpace
    Dim intFreeSpace
    Dim UsedPercentage
    on error resume next
      strDriveLetter           = WScript.Arguments(0)   'This is the drive letter which you want to monitor on the localhost
      DiskFreePct              = WScript.Arguments(1)   'This is the threshold percentage of free space
      ThresholdGB              = WScript.Arguments(2)
      Recipient                = WScript.Arguments(3)   'This is where the e-mail needs to be sent to             
    If Err.Number <> 0 Then
      msgbox "You did not supply the arguments after calling the VBS file:" & vbcrlf & "<Drive Letter, eg:  C:>"& vbcrlf & "<Warning Threshold in Percentage> "& vbcrlf &"<Warning Threshold in GB Remaining> "&
    vbcrlf &"<Recipient E-Mail Address>"
      WScript.Quit
    End If 
    strComputer = "."
    'WScript.Echo strComputer
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    'WScript.Echo WshNetwork.ComputerName
    arrServerList = array(strComputer)    'This is where your local host will be used as the query
    Do until i = 1
        'Clear the message variable
        strMessage = ""
        'Poll the array of servers
        PollServers strComputer,strDriveLetter
        'Email if there is a message
        if strMessage <> "" then
            EmailAlert(strMessage)
        end if
        'The script will loop for now just for testing. Uncomment the line that follows the loop logic to cancel the loop.
        'WScript.Sleep(WaitTimeInMinutes*60000)
            i = i + 1
    Loop
    Sub PollServers(strComputer,strDriveLetter)
        Selectstring = "Select * from Win32_LogicalDisk Where DeviceID = '" & strDriveLetter & "'"
        on error resume next
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colItems = objWMIService.ExecQuery(Selectstring)
        For Each objItem in colItems
     if objItem.FreeSpace/objItem.Size * 100 <= DiskFreePct or mbFreeSpace <= ThresholdGB then
         DrivePercentage = FormatNumber(objItem.FreeSpace/objItem.Size *100,0)
         DriveSpaceRem   = FormatNumber((objItem.FreeSpace/1024000),0)
         intFreeSpace    = objItem.FreeSpace
         mbFreeSpace     = intFreeSpace / 1024 / 1024 / 1024
         mbFreeSpace     = round(mbFreeSpace,0)
         intTotalSpace   = objDisk.Size
         UsedPercentage  = 100 - DrivePercentage
              strMessage      = strMessage & " "
            end if
        Next
    End Sub
    Sub EmailAlert(Message)
        on error resume next
        Set objMessage = CreateObject("CDO.Message")
     with objMessage
            .From = emailFrom
            .To = Recipient
            .Subject = "" & WshNetwork.ComputerName & ": Alert " & Now & " -> " & UCase(strDriveLetter) & " fill level = " & UsedPercentage & "%, Space Remaining = " & mbFreeSpace & "
    GB"
            .TextBody = Message
            .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
            .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ExchangeServer
            .Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
            .Configuration.Fields.Update
            .Send
        end with
        Set objMessage = Nothing
    End Sub
    'WScript.Echo "done"

  • Invoking a AXIS Web Service with a Java object as input argument

    Hi
    I've been trying to execute a bpel process that invokes a web service deployed through axis.
    This web service takes a java object as input argument as opposed to data types that are directly mapped to java types through the SOAP engine.
    I deployed and tested the service outside of BPEL using a test client class. Everything works well.
    When I try to configure the "Assign" and "Invoke" activities so that service can be invoked, I cannot see the data structure through the variable picker and I see the following message:
    "The element {urn:ComplexTypeWebService}TimeSheetBean is not know to the schema container. Perhaps a schema file that uses it needs to include or import its definition.There mat also be an XML schema issue (non resolvable schema) which prevents {urn:ComplexTypeWebService}TimeSheetBean from being seen by the schema processor."
    Is there any example that demonstrates how to invoke an axis web service in such scenario? What am I doing wrong?
    Please, let me know.

    The passing of Java objects in and out of a web service is NOT supported. variables must be xml documents defined by a XML schema. In my opinion, missing Java object and WSDL is not a good idea. -Edwin

  • Object Required: 'Wscript'

    I've used the below VB script in my .hta application for selecting the folder. But when there is no folder is selected and I click 'Cancel' button then am getting Script error: Object Required: 'Wscript'.
    Sub ButtOutFolder
      Const MY_COMPUTER = &H11&
    Const WINDOW_HANDLE = 0
    Const OPTIONS = 0
    Set objShell      = CreateObject("Shell.Application")
    Set objFolder     = objShell.Namespace(MY_COMPUTER)
    Set objFolderItem = objFolder.Self
            strPath = objFolderItem.Path
    Set objFolder = objShell.BrowseForFolder _
    (WINDOW_HANDLE, "Select a folder:", OPTIONS, strPath)
    If objFolder Is Nothing Then
    Wscript.Quit
    End If
    Set objFolderItem = objFolder.Self
    objPath = objFolderItem.Path
            OUTFOLDERPATH = objPath
            OutpathTxt.value = OUTFOLDERPATH
    End Sub

    Simple example:
    <html>
    <head>
    <title>My HTML Application</title>
    <script language="vbscript">
    Sub ButtOutFolder
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder(0, "Select a folder:", 0)
    If objFolder Is Nothing Then
    MsgBox "No folder selected -CANCELED"
    Exit Sub
    End If
    txtFolderPath.value = objFolder.Self.Path
    End Sub
    </script>
    <hta:application
    applicationname="MyHTA"
    border="dialog"
    borderstyle="normal"
    >
    </head>
    <body>
    <input type="button" Value="Select Folder" onclick="ButtOutFolder">&nbsp;<input id="txtFolderPath" type="text" size="65">
    </body>
    </html>
    ¯\_(ツ)_/¯

  • How to access the remote Objects Without Db_links?

    Hi ,
    I want to know how to access the remote objects without db_link.That is i want to access a object in some other server which has different database.

    SanjayBala, just so you know that it is possible to create a database link in Oracle to non-Oracle databases in some circumstances. Look up Generic Connectivity aslo know as Heterogenous Services. With 11g Oracle has basically renamed the feature and replaced it with somethinkg named ike DG4ODBC.
    I have not spent time studying the details for DB4ODBC but with HS Oracle provided the interface and you had to obtain the necessary ODBC driver on your own. I had Oracle on AIX reading and writing to SQL Server on Windows but the developers chose to write a java program and connect to both via it. On Windows and Linux platforms the necessary ODBC drivers might be available without the requirement to go out and purchase one.
    The Oracle Open Gateway product is an advanced version of the above features with drivers for specific non-Oracle databases included like DB2 or Informix.
    HTH -- Mark D Powell --

  • Program Objects Stuck in Running Status

    I have some batch files that runs as  scheduled program objects in Business Objects XI.  They will work correctly for a week or so and then they stay stuck in running status without completing, with several jobserverchild.exe processes running and several folders still in the procSched folder.  I can sometimes delete the processes and the folders and get it to work and sometimes not.  Anybody know the problem

    Anybody have any idea about this? I am still having the problem

  • Extending object, without calling super constructor

    public class Object1
        byte index;
        public Object1(byte i)
            index = i;
    public class Object2 extends Object1
        private byte j;
        public Object2() {
            super((byte) 0);
        public void setIndex(byte i)
            j = i;
    import java.util.*;
    public class Test1
        private ArrayList<Object1> aList;
        public Test1()
            aList = new ArrayList<Object1>();
        public void run()
            for (byte i = 0; i < 10; i++)
                aList.add(new Object1(i));
        public ArrayList<Object1> getResults()
            return aList;
    import java.util.*;
    public class Test2
        ArrayList<Object1> results;
         * Constructor for objects of class Test2
        public Test2()
            Test1 t1 = new Test1();
            t1.run();
            results = t1.getResults();
        public void run()
            Iterator<Object1> i = results.iterator();
            while (i.hasNext())
                Object2 o2 = (Object2) i.next();
    public class Test3
        public static void main(String[] args)
            Test2 t2 = new Test2();
            t2.run();
    }There are two things with this code that I'm having problems with.
    1. I want to create an object of class Object1 in Test1. That works fine. In Test2 I then want to extract the object from the ArrayList, but since Object2 extends Object1, I want to get an Object2 out from the ArrayList. However with the code above, I get a ClassCastException. If I leave out the cast, I get an incompatible types error.
    2. I want Object2 to be an extension of Object1, that is, with more fields and methods. But I have no need to create an object of class Object2, since I know I already have an ArrayList of Object1. So I want to remove the constructor from Object2, seeing as I won't need it. However, if I remove the super part (which, again, is not needed, as I will already have created my needed objects of class Object1 when I get there, and only need to EXTEND my Object1 objects), I get a cannot find symbol, constructor Object1() error.
    I'm not sure that I can solve problem 2 without using a super. But I am convinced that I must be able to get the Object1 objects out as Object2 instead. I would just like some help with how to do that.

    ThemePark wrote:
    But I am convinced that I must be able to get the Object1 objects out as Object2 instead. I would just like some help with how to do that.Maybe you don't understand how inheritance works. Go read a basic tutorial on inheritance. You can use an Object2 as an Object1, but not an Object1 as an Object2. You either have to create Object2 objects in the first place; or have to make a wrapper class that takes an Object1 and passes things to the Object1 object; and use objects of this wrapper class.

  • What is the program object is being created when we activate smartform?

    What is the program object is being created when we activate smartform?

    hi,
    while activate the smart form, a function module is being created.
    by using this function module we can pass the business data to the form.
    in print program we can simply call the function module which has been created by smart form while it activate and pass required parameters to it.
    for more information follow this link.
    http://sap.niraj.tripod.com/id67.html
    regards,
    Ashok Reddy

  • Passing a string as an object name...how?

    I've searched all over the place for a solution to this to no avail.
    I have a program that reads input from a text file. The text file holds information on student IDs, so it look something like this:
    "ID_1234"
    "ID_1235"
    "ID_1236"
    So, every line of the text file has a student ID.
    I have a class called Student, that takes the student ID as a parameter, so I can create a Student object pretty easily by going, for example:
    Student newStudent = new Student("ID_1234");
    Now, my problem is that I want to read the contents of the text file that is given to me and create an object for each student, and use as a name for that object the student's ID. I have the program reading the data from the text file no problem, it's just the object name assignment I'm having trouble with.
    //Start code
    private void readInStudents(String fileName){
    BufferedReader reader = new BufferedReader (new FileReader (studentIDFile.txt));
    String line = reader.readLine();
    while(line != null)
    Student line = new Student(line);
    //End code
    Ideally I would like this to crate three Student objects, with the names "ID_1234", "ID_1235", and "ID_1236" respectively.
    However, this is not the case as I get an error when assigning "line" as the object name in the line within the while loop.
    Any help would be much appreciated!!!!!!
    Many thanks.

    elsombreron wrote:
    Thanks to all for your quick replies. I ended up using an ArraList to store the objects without needing to give them all a dynamic name.
    I come from a purely procedural programming background where the sort of assignment I was trying to do would work, so still have to get used to OO style.
    Thanks again.Huh? I don't see what procedural vs object oriented has to do with it.
    FORTRAN, COBOL, C and Ada (pre 95) are all procedural languages and as far as I can remember, you could not do that in any of them.
    Perhaps many scripting languages allow this. The various *nix shells come to mind.
    What languages are you referring to that have tis feature?

  • Instantiating an object without an assignment

    Hi,
    I am learning Java. I would like to know what is the significance of instantiating an object without an assignment.
    I have created a class TestClass1 with a single constructor that prints a test message.
    In TestClass2, if I write "new TestClass1()" rather than "TestClass1 x = new TestClass1()" it still works, and prints the test message.
    I would like to know if I do not assign an object at the time of instantiation, it cannot be referenced or reused later, then what is the significance of this type of construct and when it can be useful, and where is the object being held.
    public class TestClass1 {
       TestClass1() {
         System.out.println("This is a test message");
    public class TestClass2 {
      public static void main (String... args) {
        TestClass1 x = new TestClass1();  //This prints "This is a test message"
        new TestClass1();                 //This also prints "This is a test message"
        String y = new String("abc");  //this makes sense
        //The following does not throw an exception - what purpose could this conceivably serve
        new String("def");               

    SRAY01 wrote:
    Sorry for using the wrong terminology - I mean a method is invoked rather than instantiated.
    A Constructor can be treated as a special type of method to instantiate an object of the class - but it does not have any expressed return type - so I assumed it implicitly returns an object (of same type as the class the contructor belongs to).
    But syntactically its usage is sort of similar to invoking a method (apart from the "new" keyword).
    I was wondering how is it possible that a constructor or a method with a return value could be called in a code without an assignment. I assumed it should be possible only for void type of methods.
    But apparently its a feature of Java. This feature is very different from any programming language I have worked with so far, e.g. PL/SQL where you cannot call a function with a return value without assigment.
    No the constructor doesn't 'return' anything.
    Construction is done by the new expression.  As PART of the execution of the new expression the constructor is called.  The new expression does other things besides just call the constructor.  For instance it allocates space and it is also responsible for returning the object.  And this is also true for languages like C# and C++ as well.

  • Powershell to close a running program gracefully without use's interact

    I have this powershell code to close a program gracefully
    Get-Process MyProgram |   Foreach-Object { $_.CloseMainWindow() | Out-Null }
    the problem is that it will pop-up a Windows asking user to hit 'OK' or to 'Cancel'! what powershell code I can force it selects OK and not prompts for user to interact? thanks.
    Thang Mo

    Here is a workaround:
    $wshell = new-object -com wscript.shell
    $wshell.AppActivate("Microsoft Outlook")
    $wshell.sendkeys("{ENTER})
    You could send the signal to "$_.CloseMainWindow()" then check to see if it closed or is waiting for user interaction. If it is still open then run the wscript code to close it. You may want to change the "{ENTER}" to reflect the actual
    option you want to use fore example ALT + Y would select yes so you can enter that by changing the last line to:
    $wshell.Sendkeys("%(Y)")
    Or if you want to say NO:
    $wshell.Sendkeys("%(N)")
    Hope this helps.
    Regards,
    Here is a full example:
    $isOutlookOpen = Get-Process outlook*
    if($isOutlookOpen = $null){
        # Outlook is already closed run code here:
    else {
         $isOutlookOpen = Get-Process outlook*
         # while loop makes sure all outlook windows are closed before moving on to other code:
             while($isOutlookOpen -ne $null){
                Get-Process outlook* | ForEach-Object {$_.CloseMainWindow() | Out-Null }
                sleep 5
                If(($isOutlookOpen = Get-Process outlook*) -ne $null){
                Write-Host "Outlook is Open.......Closing Outlook"
                    $wshell = new-object -com wscript.shell
                    $wshell.AppActivate("Microsoft Outlook")
                    $wshell.Sendkeys("%(Y)")
                $isOutlookOpen = Get-Process outlook*
            #Outlook has been closed run code here:

Maybe you are looking for