CMD line with parameters

Simon Scott 306 Reputation points
2021-02-03T13:43:33.063+00:00

Good afternoon,

I'm trying to read a text file which contains a line of text (in this instance it says (UTC-03:00) City of Buenos Aires | Argentina Standard Time) for setting a timezone on a PC. Here is my code

Dim sString As String = Nothing
Using sr As New StreamReader("c:\temp\test.ini")
sString = sr.ReadToEnd()
End Using
Dim sSubString = sString.Substring(sString.LastIndexOf(" | ") + 1)
' MsgBox(sSubString)

 Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd", "/k" & ("tzutil.exe /s " + sSubString))
 Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()
 proc.StartInfo = procStartInfo
 proc.Start()

This is what happens when i run the program...

'Argentina' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Admin\OneDrive\Projects\Timezone\TimeZone\TimeZone\bin\Debug>

Sorry i'm only a beginner at programming. Can anyone assist me at all?

Thanks
Simon

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,983 questions
0 comments No comments
{count} votes

Accepted answer
  1. Simon Scott 306 Reputation points
    2021-02-09T20:53:50.82+00:00

    Evening,

    Thanks for your answer.

    I'm getting closer to it working but can't fathom out the last bit.

    Here's my code....

    Dim sString As String = Nothing
    Using sr As New StreamReader("c:\temp\test.ini")
    sString = sr.ReadToEnd()
    End Using
    Dim sSubString = sString.Substring(sString.LastIndexOf("|") + 1)

        Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd", "/k" & ("tzutil.exe /s " + """" + sSubString + """"))
        Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()
        proc.StartInfo = procStartInfo
        proc.Start()
    

    When i run it, i get the following message

    TZUTIL: Invalid time zone Montevideo Standard Time.
    Use TZUTIL /l for a list of valid time zones.

    If i manually type in the command tzutil /s Montevideo Standard Time, i get this

    C:\Users\Admin\OneDrive\Projects\Timezone\TimeZone\TimeZone\bin\Debug>tzutil /s montevideo Standard Time
    TZUTIL: Invalid number of arguments for /s.
    Use TZUTIL /? for a list of valid options.

    However, if i type in tzutil /s "Montevideo Standard Time" it runs succesfully!

    Therefore, how do i add quote marks either side?

    Many thanks and apologies for perhaps an obvious question

    Simon


2 additional answers

Sort by: Most helpful
  1. Castorix31 86,316 Reputation points
    2021-02-03T17:20:23.443+00:00

    You must add double-quotes around the string

    For example, if I hard-code your substring with "Argentina Standard Time" :

            sSubString = "Argentina Standard Time"
            Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd", "/k" & ("tzutil.exe /s """ + sSubString + """"))
            Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()
            proc.StartInfo = procStartInfo
            proc.Start()
    
    1 person found this answer helpful.
    0 comments No comments

  2. Xingyu Zhao-MSFT 5,366 Reputation points
    2021-02-10T06:33:02.62+00:00

    Hi @Simon Scott ,

    if i type in tzutil /s "Montevideo Standard Time" it runs succesfully!

    Try:

        Dim procStartInfo As System.Diagnostics.ProcessStartInfo =  
                New System.Diagnostics.ProcessStartInfo("cmd", "/k " & ("tzutil.exe /s '" + sSubString + "'"))  
    

    Hope it could be helpful.

    Best Regards,
    Xingyu Zhao
    *
    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.