Command prompt issue from VBscript

So I have this script that works perfectly for parsing out a COM number and then sending data to said COM port via the command line (things like 'ipconfig > //./COM15'). The issue is that it only works when I use the /K modifier which tells the command
windows to stay open.  I don't want them to stay open, but whenever I remove the /K, it doesn't work. Nothing gets copied to the COM port. I suspect the cause of this is the command prompt closing before things like systeminfo can finish running. So is
there a way to have the command prompt window stay open for a short amount of time and then close?
'Part 1: FindCOM port
fileName = "C:\rtlstuff\COM.txt"
Set regex = New RegExp
regex.Pattern = "COM(\d+)"
regex.IgnoreCase = True
regex.Global = True
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(fileName)
text = file.ReadAll()
file.Close
Dim ComPort
Set matches = regex.Execute(text)
For Each m In matches
ComPort = m.SubMatches(0)
Next
'Part 2: Set file dictionary
set oDic = CreateObject("Scripting.Dictionary")
oDic.Add 0, "ECHO %DATE% %TIME% > //./COM"
oDic.Add 1, "ipconfig > //./COM"
oDic.Add 2, "systeminfo > //./COM"
v = 3
'Part 3: Set COM Variables
Set oShell = WScript.CreateObject ("WScript.Shell")
MODE = "MODE COM" & ComPort & " 9600,N,8,1,P"
oShell.run "cmd.exe /C" & MODE
'Part 4: Data transmission
Dim Command
x=0
do while x < v
Command = oDic.Item(x) & Comport
msgbox Command
oShell.run "cmd.exe " & Command
x=x+1
wscript.sleep 10000
loop

Can you help me with syntax? I'm still not hugely familiar with VB and I'm not sure how to set this up. This current iteration does not work.
'Part 1: FindCOM port
fileName = "C:\rtlstuff\COM.txt"
Set regex = New RegExp
regex.Pattern = "COM(\d+)"
regex.IgnoreCase = True
regex.Global = True
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile(fileName)
text = file.ReadAll()
file.Close
Dim ComPort
Set matches = regex.Execute(text)
For Each m In matches
ComPort = m.SubMatches(0)
Next
'Part 2: Set file dictionary
set oDic = CreateObject("Scripting.Dictionary")
oDic.Add 0, "ECHO %DATE% %TIME% > //./COM"
oDic.Add 1, "ipconfig > //./COM"
oDic.Add 2, "systeminfo > //./COM"
v = 3
'Part 3: Set COM Variables\par
Set oShell = WScript.CreateObject ("WScript.Shell")
MODE = "MODE COM" & ComPort & " 9600,N,8,1,P"
oShell.run "cmd.exe /C" & MODE
'Part 4: Data transmission
Dim Command
i = True
x=0
do while x < v
Command = oDic.Item(x) & Comport
msgbox Command
oShell.run "cmd.exe " & Command , ,True
x=x+1
wscript.sleep 10000
loop

Similar Messages

  • Running command prompt externally from Java

    Hi,
    Does anyone know how to make a Java program that opens up the command prompt and runs certain commands? Thanks,
    Adam

    Read this before you use it:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Command Prompt Issue

    Hi everybody,
    I've dloaded the latest JDK, and have been using JCreator to compile and run programs. I do need to, however, use the command prompt to compile/execute programs as well. (e.g. javac myProgram.java) Java commands are not recognized as internal or external commands for some reason. I'm running windows XP pro, btw. Is there any way to manually fix this problem? Any help is appreciated.

    ok I think I got it to work, but I've got a noob question. To comile you type: javac filename.java, but I forgot how to run the program. I thought it was: java filename. Sorry this is such a dumb question, but I just started java.

  • Selecting different homes from command prompt

    Hi Gurus,
    Oracle client-9201
    Oracle client-10201
    Win XP SP2
    We have two oracle homes. We want to switch it from one to another. We have restriction that this should be done from command prompt only. Although I can change homes launching latest OUI and going to "INSTALLED PRODUCTS" tab where we find ENVIRONMENT tab. There it is possible to change home and apply. But this thing I want to do from command prompt.
    Any help will be highly appreciated.
    Regards.
    Virendra

    No, you don't want it to be from a command prompt and from OUI. What you want is to be able to do this without the need to visit all 400 client boxes. The method is irrelevant, as long as it efficiently achieves your real goal.That is true.
    You keep saying "command prompt" and "OUI", but can't visit all the necessary machines. So what were you envisioning? Creating some batch file you could distribute to all affected users over the network, and ask them to execute said batch file? That may (or may not) be valid, but to find the best solution we have to clearly define the real requirements and separate that from any pre-concieved solution.You can say it is my pre-concieved assumption that I will go with Command Prompt/OUI. But the real problem is I don't want to visit all machines. It can be a batch file distributed to all machines or our network people may execute it sitting on domain controller machine from which he can run programs in background of any machine in network.
    From the other things discussed on this thread, I suspect you are going to have to blow in some registry hack, by one of several possible means. But first we have to know what your real constraints are and all of the options open to you.Real constraint is, We don't want (rather can't) visit all 400 terminals.
    Do you have the ability to push registry settings at client logon?Yes, We can.
    Can you guarantee the consistency of configuration of all 400 clients?Home name and Location may be different on different machines.
    Do you have the ability to force the automatic execution of a command file from a file server and client log-on time?Yes, it is possible.
    Are you working with your network people to explore what help they might be able to provide on the above points?They may help us depending upon the requirement.
    Regards
    Virendra

  • How to read Command Prompt?

    Hello!
    In my application i need to read information from Command Prompt. From other programmers i knew that method : System.in.read(); state for it. But I get the whole bunch of error messages from compiler.
    If you know concrete URL's or web sites where I can learn about this function, please reply to me.
    I will appreciate any help.
    Thank you in advance
    Michael

    System.in.read() throws a java.io.IOException. Did you put try/catch statement to catch this exception ?
        try {
            System.in.read();
        catch(java.io.IOException ioException) {}

  • Command prompt window problem

    Hi,
    Can anyone tell me how to open a command prompt window from a Java GUI application? The application is started as a excutable JAR file and there is no command prompt window showing up in the beginning.
    Thanks a lot
    Wenly

    Thank you guys, I have checked the doc and it seems the Runtime.getRuntime().exec(); will start a seperated process.What I need is to open a command prompt window in the same process of my application and display message on it by using System.out.println()
    Is it possible?

  • How to get no. of rows of Windows Command Prompt in java

    hi all,
    can anybody tell me that is there any java utility avalilable throght I can find the how many rows avalilbe on currently executing command prompt, and also how can i clear the content of command prompt (result of 'cls' command).
    Currently execting command prompt means from where I have run my java program.
    any reference is also welcome.
    thanks in advance.

    Clearing the screen is trivial, as long as you're OK with making your program specific to Windows only (i.e. you never hope to run it on any other OS ever):
    Runtime.getRuntime().exec("cmd /c cls");As to figuring out how many lines your command window's screen buffer has - good luck with that. I'm not familiar enough with the Win32 API to get this info, but you'll have to figure out what that is, and call it via JNI.

  • Freezing a JFrame and hiding teh command prompt

    Hay all,
    I have 2 simple questions!
    1- Is there a method to prevent a jframe from being moved (dragged) by the user around the screen and thus stay in the place set by its setBounds (..) method?
    2- Is there a way to prevent the command prompt screen from showing while an application is being run????
    Thanks alot ,

    1- Is there a method to prevent a jframe from being
    moved (dragged) by the user around the screen and
    thus stay in the place set by its setBounds (..)
    method?componentMoved event on the ComponentListener. Listen for it, and when the component is moved, put it back to where you want it. I'm not sure that there is a way to make a JFrame immovable.
    2- Is there a way to prevent the command prompt
    screen from showing while an application is being
    run????javaw.exe
    -Dave

  • VBScript Runs Correctly From Command Prompt, But Not From SQL Server Agent Job

    I'm trying to run this script on my local machine to do some post-batch cleanup and it doesn't run correctly from the scheduled job (or when I invoke the job).
    Here's the script in question:
    Option Explicit
    Const filePath = "C:\Documents and Settings\jmunn\My Documents\Visual Studio 2008\Logs\"
    Const holdDays = 6
    main
    Sub Main()
    ClearArchive
    End Sub
    Sub ClearArchive()
    Dim fso 'As Scripting.FileSystemObject
    Dim fld 'As Scripting.Folder
    Dim f 'As Scripting.File
    Dim delLogName, delLogOut, delCtr
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set fld = fso.GetFolder(filePath)
    delLogName = filePath & "Nightly Backup - Backup Logs Deleted" & ".txt"
    Set delLogOut = fso.CreateTextFile(delLogName, True)
    delLogOut.WriteLine(delLogName)
    delLogOut.WriteLine("")
    delLogOut.WriteLine("-- The following log files were deleted on " & DateValue(Now()) & " at " & TimeValue(Now()))
    delLogOut.WriteLine("")
    delCtr = 0
    For Each f In fld.Files
    If Left(f.Name, 48) = "Nightly Backup - SQL Server Databases_Subplan_1_" And Right(LCase(f.Name), 4) = ".txt" Then
    If DateDiff("d", f.DateCreated, Date()) > holdDays Then
    delLogOut.WriteLine(f.Name)
    fso.DeleteFile f, True
    delCtr = delCtr + 1
    End If
    End If
    Next
    If delCtr = 0 Then
    delLogOut.WriteLine("No log files were deleted this run...")
    End If
    Set fld = Nothing
    Set fso = Nothing
    delLogOut.Close
    End Sub
    If I put the script in its own file and run it from the command prompt, it runs just fine. If the script runs from the SQL Server Agent job, the for-loop will delete the files correctly, but the filenames
    do not get written to the deletion log file and the counter does not get incremented, so according to the job log, nothing was deleted. Why does the script run differently from each invocation? It can't be a permission thing, the service that logs in has full
    access to the directory and the files do get deleted. Any ideas out there?
    Between this and other outstanding issues, I'm quickly losing faith in SQL Server.  >=o(
    Thanks in advance for your thoughts!
    John
    Version Info:
    Microsoft SQL Server Management Studio      10.0.2531.0
    Microsoft Analysis Services Client Tools      10.0.1600.22
    Microsoft Data Access Components (MDAC)      3.85.1132
    Microsoft MSXML      2.6 3.0 4.0 5.0 6.0
    Microsoft Internet Explorer      8.0.6001.18702
    Microsoft .NET Framework      2.0.50727.3603
    Operating System      5.1.2600
    "A bus station is where a bus stops. A train station is where a train stops. On my desk I have a workstation..."

    Hi
    jrmunn
    i am trying to execute VB script to refresh my excel files.. using Vbscript file through SQL Agent job step.
    i have copied VBscript in a file with the extension RefreshExcel.vbs kept in C:\RefreshExcel.vbs
    Below is the script used inside the file (RefreshExcel.vbs)
    //---Script code-----------------------------------------------------------------
    Dim objXL, objWB
    Dim FileLocation, FileName
    On Error Resume Next
    'lgnConn = 1
    FileLocation = "F:\Reports\Reports"
    Set objXL = CreateObject("Excel.Application")
    objXL.DisplayAlerts = False
    FileName = "ReportFile1.xlsx"
    'MsgBox (FileLocation & "/" & FileName)
    Set objWB = objXL.Workbooks.Open(FileLocation & "/" & FileName)
    objWB.EnableConnections
    objXL.CalculateUntilAsyncQueriesDone
    objWB.RefreshAll
    objXL.CalculateUntilAsyncQueriesDone
    objWB.RefreshAll
    objXL.CalculateUntilAsyncQueriesDone
    objWB.Save
    objWB.Close
    Set objWS = Nothing
    Set objWB = Nothing
    objXL.Quit
    Set objXL = Nothing
    'MsgBox ("Refresh Completed")
    ---------------------------------------------------------------------------------------------------//Script complete
    Now when i am trying to call this script file in SQL agent job step (as you mentioned )
    as Type -cmdExec(OperatingSystem)
    cscript "C:\RefreshExcel.vbs"
    Issue: job step executed succesfully ,,but without performing any refresh on the excel. So i am not understandig what is going wrong. the same script file work when i am calling it through a batch file (window scheuler task). But it doesnt support
    to run the file "when user is not logged in"
    that is why  i want to refresh my excel file through sql agent ,which can be scheduled to any time and cab be run as SQL agent credentials.
    Can you please help me on this ...i have tried all the option but nothing working .. found hope by seeing your solution.
    Thanks in advance.
    Please help me. :-(

  • Issues executing report from command prompt

    I'm using Oracle 10g Reports and attempting to execute a report from my workstation to output in a spreadsheet format. We don't have a Reports Server implemented at this time, so I'm simply connecting to the database with Reports Builder and running reports. I can execute a report just fine from Reports Builder and output as PDF; however I'm not familiar with how to output as spreadsheet. From what I understand, spreadsheet output cannot be accomplished through the tool, only from the command prompt. I've tried executing the a command inthe following format from Windows XP command prompt, but no luck:
    rwrun report=test_report.rdf userid=[usernam/pwd@db] desformat=spreadsheet destype=file desname=c:\temp\test_report.xls
    Nothing occurs...no output, nothing when this command is entered. What is the issue? Can rwrun.exe even be used for executing on the client-side? According to Oracle documentation, rwrun is the executable that runs a report using the OracleAS Reports Services.

    Hello,
    Even if the parameter is deprecated, you can use errfile=c:\temp\reports.err and check if there are some errors ..
    or check for a file reports.log
    Regards

  • Error when running a scenario from Command Prompt

    Hi I edited the parameter file and I am trying to run an interface that joins two tables from HR schema and loads into a table in different schema. I am able to run this in the Designer, but I receive an error message when I try to run it through command prompt.
    Here is the error message I get when I try to run it
    09/09/2009 11:58:42 AM(main): Creating session for scenario:DEMO_INTERFACE - 001
    09/09/2009 11:58:42 AM(main): Session : 88010 is running
    com.sunopsis.core.SnpsInexistantObjectException: There is no connection for this
    logical schema/context pair:HR / GLOBAL
    at com.sunopsis.dwg.dbobj.SnpConnect.getSnpConnectByLSchemaNameAndContex
    t(SnpConnect.java)
    at com.sunopsis.dwg.dbobj.SnpConnect.getSnpConnect(SnpConnect.java)
    at com.sunopsis.dwg.dbobj.SnpSession.getDwgConnectLst(SnpSession.java)
    at com.sunopsis.dwg.dbobj.SnpSession.getConLst(SnpSession.java)
    at com.sunopsis.dwg.cmd.DwgCommandScenario.treatCommand(DwgCommandScenar
    io.java)
    at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
    at com.sunopsis.dwg.cmd.e.i(e.java)
    at com.sunopsis.dwg.cmd.e.y(e.java)
    at com.sunopsis.dwg.DwgJv.treatCmd(DwgJv.java)
    at com.sunopsis.dwg.DwgJv.main(DwgJv.java)
    at oracle.odi.Agent.main(Agent.java)
    09/09/2009 11:58:43 AM(main): Session : 88010 finished with return code : -1
    com.sunopsis.core.SnpsInexistantObjectException: There is no connection for this
    logical schema/context pair:HR / GLOBAL
    at com.sunopsis.dwg.dbobj.SnpConnect.getSnpConnectByLSchemaNameAndContexur
    t(SnpConnect.java)
    at com.sunopsis.dwg.dbobj.SnpConnect.getSnpConnect(SnpConnect.java)
    at com.sunopsis.dwg.dbobj.SnpSession.getDwgConnectLst(SnpSession.java)
    at com.sunopsis.dwg.dbobj.SnpSession.getConLst(SnpSession.java)
    at com.sunopsis.dwg.cmd.DwgCommandScenario.treatCommand(DwgCommandScenar
    io.java)
    at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
    at com.sunopsis.dwg.cmd.e.i(e.java)
    at com.sunopsis.dwg.cmd.e.y(e.java)
    at com.sunopsis.dwg.DwgJv.treatCmd(DwgJv.java)
    at com.sunopsis.dwg.DwgJv.main(DwgJv.java)
    at oracle.odi.Agent.main(Agent.java)
    DwgJv.main: Exit. Return code:-1
    Thank you for your help.
    Kranthi

    Hello,
    Try to remove and recreate your package and scenario, I had the same issue and solved doing it.
    It seems for me that the package cannot update its contents, for example, if you change something in your interface, you must recreate your package and scenario to update the changes.
    What ODI version do you use? If you use an old version, try to update to ODI 10.1.3.5
    Regards,
    Wallace Galvão
    São Paulo - Brazil

  • Copy and Paste from PDF to Command Prompt

    Hi,
    When I convert a Word doc to PDF, that includes instructions to the user to cut and paste commands from the doc into the command prompt window, the pasted text is rejected by the command prompt window.
    I recently upgraded to the Adobe Technical Communication suite. Prior to this I was using Word's native convert to PDF plugin. None of the text in PDFs generated by this method causes any issue. I remade the PDF using this method after the previous one made with Acrobat caused issues and it worked fine.
    I would like to continue using Acrobat because the auto-generated bookmarks are a nice feature for the end-user.
    Any suggestions?
    Thanks,
    Donal

    Hi Donal,
    This forum is 3D issue specific. Your quesrtion would be better handled on the Acrobat User-toUser forum. There are many brilliant folks there who might be able to answer your very quickly.

  • Can't create database from command prompt

    I am using Oracle 9i over Win XP. I can create new database using OEM wizard without any problem. However, when I try to create new database from command prompt, using following commands, I get an error.
    sqlplus /nolog
    connect / as internal (when I issue this I get message TNS no listener)
    CONNECT SYS/password AS SYSDBA (can't understand how to use this, I don't have password because I've not created the database)
    Can anyone help me how to create new database from command prompt?
    Thanx

    "TNS No Listener" => Start the listener
    To be connected as SYSDBA you dont need a password if your are logged in the DBA group, you just have to :
    PROD_:id
    uid=102(oracle) gid=103(oinstall)
    PROD_:sqlplus "/ as sysdba"
    SQL*Plus: Release 8.1.7.0.0 - Production on Wed Jul 23 11:46:50 2003
    (c) Copyright 2000 Oracle Corporation. All rights reserved.
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - Production
    SQL> show user
    USER is "SYS"
    SQL>
    Fred

  • Not able to start managed server from command prompt

    Hi,
    I am trying to start manged server from command prompt. The command i am using is as follows:
    startManagedWebLogic.cmd MS1 [http://]&lt;Listen_Address&gt;:&lt;Admin_port&gt;
    Where MS1 is the name of my managed server.
    But i am getting following exceptions:
    There are 1 nested errors:
    weblogic.management.ManagementException: Unable to obtain lock on C:\bea\user_pr
    ojects\domains\PB530Domain\servers\AdminServer\tmp\AdminServer.lok. Server may a
    lready be running
    at weblogic.management.internal.ServerLocks.getServerLock(ServerLocks.ja
    va:159)
    at weblogic.management.internal.ServerLocks.getServerLock(ServerLocks.ja
    va:58)
    at weblogic.management.internal.DomainDirectoryService.start(DomainDirec
    toryService.java:73)
    at weblogic.t3.srvr.ServerServicesManager.startService(ServerServicesMan
    ager.java:459)
    at weblogic.t3.srvr.ServerServicesManager.startInStandbyState(ServerServ
    icesManager.java:164)
    at weblogic.t3.srvr.T3Srvr.initializeStandby(T3Srvr.java:711)
    at weblogic.t3.srvr.T3Srvr.startup(T3Srvr.java:482)
    at weblogic.t3.srvr.T3Srvr.run(T3Srvr.java:440)
    at weblogic.Server.main(Server.java:67)
    >
    <Feb 10, 2009 6:48:16 PM IST> <Notice> <WebLogicServer> <BEA-000365> <Server sta
    te changed to FAILED>
    <Feb 10, 2009 6:48:16 PM IST> <Error> <WebLogicServer> <BEA-000383> <A critical
    service failed. The server will shut itself down>
    <Feb 10, 2009 6:48:16 PM IST> <Notice> <WebLogicServer> <BEA-000365> <Server sta
    te changed to FORCE_SHUTTING_DOWN>
    Please help me to resolve this issue.
    thanks,
    Sonal
    Edited by: [email protected] on Feb 10, 2009 5:16 AM

    Looking at your error message a little closer, I don't believe it has anything to do with port conflicts but rather that even though you are executing the startManagedWeblogic.cmd with your managed server name (MS1), the error indicates that it is trying to start the Admin Server (not MS1). Note in your error message the following: Unable to obtain lock on C:\bea\user_pr
    ojects\domains\PB530Domain\servers\AdminServer\tmp\AdminServer.lok. Server may a
    lready be running
    It is saying that it cannot start the Admin Server because it is already running (which is probably true in your case). Have you made any changes to the startManagedWeblogic.cmd or the startWeblogic.cmd scripts? I would start debugging there and try to figure out why the script is trying to start your admin server instead of MS1 as you requested on the cmd line.

  • Calling command prompt from inside a servelt?

    Hello all, I have an issue with calling the command prompt cmd.exe from inside a servlet to perform a .rtf to .pdf conversion for me. I believe the problem might be more Windows permissions oriented but I will see what you think? (I am at a loss on this one) I am using the standard call of -
    Process proc = Runtime.getRuntime().exec("cmd.exe /c C:\\BatchPDF.exe "+rtfFile.getAbsolutePath()+" "+pdfFile.getAbsolutePath());
    - Just calling a .rtf file and converting it to .pdf no biggie. But! oh there is always a but!
    If I start tomcat locally using the startup.bat in the tomcat /bin dir, I have no problems with my servlet launching cmd.exe and converting the files.
    However,
    If I start tomcat as a system service from the services control pannel, My servlet just hangs and will not launch cmd.exe? Tomcat is set to start as the servers Admin account when started as a service, should this not let it open the command prompt? Also, cmd.exe has full permissions to everyone! Is it possible that it might be a Catalina Policey that is preventing this? Again, I am lost and hope someone might have had this problem and fixed it before!
    Thank You in Advance,
    Lance

    It might be because of when starting as a service it
    has no "console" (just a guess). But anyway, you don't
    need the "cmd.exe /c" part - just run the .exe(meaning, the *PDF.exe)                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for