An object-oriented programming language developed by Microsoft that can be used in .NET.
Try "/c" instead of "/k".
Maybe consider starting the program directly, without "cmd".
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Morning all,
I run the following code which works well. However it keeps creating new CMD line windows which isn't ideal as it consumes memory!
I have tried proc.kill but the process doesn't start again!
What can i do to stop the process?
Dim sSubString = sString.Substring(sString.LastIndexOf("|") + 1).Trim()
Dim procStartInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo("cmd", "/k" & ("tzutil.exe /s " + """" + 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
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden
proc.Start()
Many thanks
Simon
An object-oriented programming language developed by Microsoft that can be used in .NET.
Answer accepted by question author
Try "/c" instead of "/k".
Maybe consider starting the program directly, without "cmd".
That's it!!!
Changed /k to /c and it works as it should.
Thank you so much.
Simon
Apologies, here is the code....
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
'Test for IP address subnet
Dim sString As String = Nothing
Dim strIPAddress As String
Dim strhostname As String
Dim Prefix As String
Try
strhostname = System.Net.Dns.GetHostName()
strIPAddress = System.Net.Dns.GetHostByName(strhostname).AddressList(0).ToString()
Prefix = strhostname.Substring(0, 3)
'Check the IP address of the local machine
Dim ipArray() As String = Split(strIPAddress, ".")
' If ipArray(0) <> "10" Then
' LblShip.ForeColor = Color.Red
' LblStatus.ForeColor = Color.Red
' LblShip.Text = "Unable to identify location"
' LblStatus.Text = "Timezone not updating, check IP address!"
' Exit Sub
' End If
'Test
If ipArray(1) = "168" And ipArray(2) = "150" Then
LblShip.Text = "This PC is at Head Office"
Using sr As New StreamReader("c:\temp\timezone.ini")
sString = sr.ReadToEnd()
End Using
Else
LblShip.ForeColor = Color.Red
LblStatus.ForeColor = Color.Red
LblShip.Text = "Unable to identify location"
LblStatus.Text = "Timezone not updating, check IP address!"
Exit Sub
End If
Catch ex As Exception
MsgBox(ex.Message)
Exit Sub
End Try
Dim sSubString = sString.Substring(sString.LastIndexOf("|") + 1).Trim()
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
procStartInfo.WindowStyle = ProcessWindowStyle.Hidden
proc.Start()
proc.WaitForExit()
The timer start event is in the form load event
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Interval = 10000
Timer1.Start()
Thanks
Simon