I am creating a start-up 2nd level logon screen for businesses and corporate companies to use. However, I am trying to disable using Task Manager by using a Registry DWORD Value. When I add in the code, it comes up with the error "Comma, ')', or a valid expression continuation expected". What can I do?
Imports Microsoft.Win32
Public Class Form1
Dim regKey As RegistryKey
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
regKey = Registry.CurrentUser.OpenSubKey("regKey.SetValue("***HKEY***\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System")
regKey.SetValue("DisableTskMgr", 1, RegistryValueKind.DWord)
End Sub
Private Sub frmMyform_FormClosing(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim Cancel As Boolean = eventArgs.Cancel
Dim UnloadMode As System.Windows.Forms.CloseReason = eventArgs.CloseReason
If UnloadMode = CloseReason.UserClosing Then
Cancel = True
End If
End Sub
End Class
My problem is with the HKEY system above. Thanks in advance!
I think this should look like this:
regKey = Registry.CurrentUser.OpenSubKey( "regKey.SetValue(""***HKEY***\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System"")" )
See Escape double quote in VB string
MsgBox("""") ' Prints a single "
Related
How do I Get the Login Cookies when am logged into a site?
I am searching for answers and now turned to StackOverflow pro members for your expertise and help to get this out of the way so I can move on to making my software.
i need to get the cookies login/visit /get/post anything how do i get it using the new webview2 browser kindly shed some light please anyone
Option Explicit
'Note, that this Demo requires the properly registered RC6-Binaries
'and in addition an installed "Chromium-Edge" (in its "evergreen" WebView2-incarnation)
'installable from its official MS-Download-URL: https://go.microsoft.com/fwlink/p/?LinkId=2124703
Private WithEvents WV As cWebView2 'declare a WebView-variable WithEvents
Private Sub Form_Load()
Visible = True '<- it's important, that the hosting TopLevel-Form is visible...
'...(and thus the Child-PicBox indirectly as well) - before we Bind the PicBox to the WebView
Set WV = New_c.WebView2 'create the instance
If WV.BindTo(picWV.hWnd) = 0 Then MsgBox "couldn't initialize WebView-Binding": Exit Sub
' Set WV = New_c.WebView2(picWV.hWnd) 'create the instance
' If WV Is Nothing Then MsgBox "couldn't initialize WebView-Binding": Exit Sub
End Sub
'*** VB-Command-Button-Handlers
Private Sub cmdNavigate_Click()
WV.Navigate "https://google.com" '<- alternatively WV.jsProp("location.href") = "https://google.com" would also work
'the call below, just to show that our initially added js-functions, remain "in place" - even when we re-navigate to something else
WV.jsRunAsync "test", 2, 3
End Sub
Private Sub WV_NavigationCompleted(ByVal IsSuccess As Boolean, ByVal WebErrorStatus As Long)
Debug.Print "NavigationCompleted welaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
End Sub
Private Sub picWV_Resize() 'when the hosting picBox got resized, we have to call a syncSize-method on the WebView
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End Sub
Private Sub picWV_GotFocus() 'same thing here... when the hosting picBox got the focus, we tell the WebView about it
If Not WV Is Nothing Then WV.SetFocus
End Sub
'*** the above two EventHandlers (of the hosting VB-PicBox-Container-Ctl) are basically all what's needed "GUI-Binding-wise"
'*** the rest of the EventHandlers below, are raised by the WebView-instance itself
Private Sub WV_InitComplete()
Debug.Print "WV_InitComplete"
End Sub
'Private Sub WV_NavigationCompleted(ByVal IsSuccess As Long, ByVal WebErrorStatus As Long)
'Debug.Print "WV_NavigationCompleted"
'End Sub
Private Sub WV_DocumentComplete()
Debug.Print "WV_DocumentComplete"
End Sub
Private Sub WV_GotFocus(ByVal Reason As eWebView2FocusReason)
Debug.Print "WV_GotFocus", Reason
End Sub
Private Sub WV_JSAsyncResult(Result As Variant, ByVal Token As Currency, ByVal ErrString As String)
Debug.Print "WV_JSAsyncResult "; Result, Token, ErrString
Text2.Text = Result
End Sub
Private Sub WV_JSMessage(ByVal sMsg As String, ByVal sMsgContent As String, oJSONContent As cCollection)
Debug.Print sMsg, sMsgContent
Select Case sMsg
Case "btn1_click": MsgBox "txt1.value: " & WV.jsProp("document.getElementById('txt1').value")
End Select
End Sub
Private Sub WV_LostFocus(ByVal Reason As eWebView2FocusReason)
Debug.Print "WV_LostFocus", Reason
End Sub
Private Sub WV_UserContextMenu(ByVal ScreenX As Long, ByVal SreenY As Long)
Debug.Print "WV_UserContextMenu", ScreenX, SreenY
End Sub
I am trying to set some images's visibility to false by using CallByName and a loop through the objects.
here is the code
Private Sub command1Click
dim theobj_str as string
dim ctr as integer
for ctr = 1 to 3
theobj_str = "Images" & ctr
CallByName theobj_str, "Visible", vbLet,False
end for
END SUB
It throws an error "TYPE MISMATCH" on "CallByName **theobj_str**..."
The CallByName takes an object as its first argument. I need to somehow convert the string "theobj_str" into an object. How can I do this ?
The CallByName works fine if I call it like : CallByName Images2, "Visible", vbLet,False
Thanks
If you don't need to use CallByName you could loop through the controls collection and check the type. If the type matches the control you want to hide then you can set it's visible property that way.
The code would look like this:
Private Sub Command_Click()
SetControlVisibility "Image", False
End Sub
Private Sub SetControlVisibility(ByVal controlType As String, ByVal visibleValue As Boolean)
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeName(ctrl) = controlType Then
ctrl.Visible = visibleValue
End If
Next
End Sub
Doing it this way will allow you to add more image controls to your form without having to remember to change your counts in the for loop.
Hope that helps.
I am building a program in visual-studio to check and fix drive using the cmd chkdsk command
I have been able to display the list of drive available is a dataGridview
I want to run chkdsk command on any selected drive(by the user) please how do I achieve that successfully. Furthermore I want the process and result of the chkdsk to be displayed on a textbox.
problem is the drives are displaying but when one is select and i click on the button fix is dose not execute(i.e fix the drive and show result&process in the textbox) Any help/code/suggestion will b appreciated, please note this is note a console application. My code are on is posted here as requested. i added the subs were i feel the problem could be from. , but if you want me to add more of my other subs i will.
Public Class Form2
Private binder As New BindingSource
Private drives As New BindingList(Of DriveInfo)
Private psi As ProcessStartInfo
Private cmd As Process
Private Delegate Sub invokeWithString(ByVal text As String)
Dim BackgrounndWorker1 As New BackgroundWorker
Private Shadows Sub OnClick(sender As Object, e As EventArgs) Handles btnfix.Click
If TypeOf sender Is Button Then
Dim btn = DirectCast(sender, Button)
btn.Enabled = False
If btn.Equals(btnfix) Then
Ddrives.Enabled = False
pgb.Visible = True
BackgroundWorker1.RunWorkerAsync(New List(Of DriveInfo)(From drive As DriveInfo In cldrive.CheckedItems Select drive))
End If
End If
End Sub
Private Sub OnDoWOrk(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
If TypeOf sender Is BackgroundWorker Then
Dim worker As BackgroundWorker = DirectCast(sender, BackgroundWorker)
If e.Argument IsNot Nothing AndAlso TypeOf e.Argument Is IEnumerable(Of DriveInfo) Then
Dim drives As IEnumerable(Of DriveInfo) = DirectCast(e.Argument, IEnumerable(Of DriveInfo))
For Each drive As DriveInfo In drives
Try
cmd.Kill()
Catch ex As Exception
End Try
TextBox1.Text = ""
psi = New ProcessStartInfo("Chkdsk /f")
Dim systemcoding As System.Text.Encoding =
System.Text.Encoding.GetEncoding(Globalization.CultureInfo.CurrentUICulture.TextInfo.OEMCodePage)
With psi
.UseShellExecute = False
.RedirectStandardError = True
.RedirectStandardOutput = True
.RedirectStandardInput = True
.CreateNoWindow = True
.StandardOutputEncoding = systemcoding
.StandardErrorEncoding = systemcoding
End With
cmd = New Process With {.StartInfo = psi, .EnableRaisingEvents = True}
AddHandler cmd.ErrorDataReceived, AddressOf Async_data_received
AddHandler cmd.OutputDataReceived, AddressOf Async_data_received
Try
cmd.Start()
cmd.BeginOutputReadLine()
cmd.BeginErrorReadLine()
Catch ex As System.ComponentModel.Win32Exception
End Try
Next
End If
End If
End Sub
Private Sub Async_data_received(ByVal sender As Object, ByVal e As DataReceivedEventArgs)
Me.Invoke(New invokeWithString(AddressOf Sync_output), e.Data)
End Sub
I have the following code in VB6
Private Sub Command1_Click()
Dim encryptedFileName As String
Dim decrypToFileName As String
encryptedFileName = "Some File Name"
decrypToFileName = "Some Other File Name"
Dim afileDecryptor As fileDecryptor
afileDecryptor = New fileDecryptor
afileDecryptor.Decrypt(encryptedFileName, decrypToFileName)
End Sub
class FileDecryptor has the following Sub:
Public Sub Decrypt(ByVal fileNameToDecrypt As String, ByVal decrypToFileName As String)
End Sub
I keepp geting compiler errot, Expected:= on the line
afileDecryptor.Decrypt(encryptedFileName, decrypToFileName)
I have looked at the everything I can , and still don't understand what the problem is
Subs don't return anything so you shouldn't have the parentheses around it's parameters.
afileDecryptor.Decrypt encryptedFileName, decrypToFileName
I was following this MSDN guide on creating custom events. I feel like I understand the process now, but I cannot figure out why I am getting a Compile Error: Event Not Found for RaiseEvent ItemAdded. The weird thing is, the ItemAdded event is recognized by the IDE (I can type it in all lowercase and it is then automatically formatted properly), so I know that it is recognized by VB.
DataComboBox Class Module Code:
Public Event ItemAdded(sItem As String, fCancel As Boolean)
Private pComboBox As Control
Public Property Set oComboBox(cControl As Control)
Set pComboBox = cControl
End Property
Public Property Get oComboBox() As Control
oComboBox = pComboBox
End Property
Private Sub Class_Initialize()
End Sub
Private Sub Class_Terminate()
End Sub
The UserForm contains two controls - a CommandButton named btnAdd and a ComboBox named cboData.
UserForm Code:
Private WithEvents mdcbCombo As DataComboBox
Private Sub UserForm_Initialize()
Set mdcbCombo = New DataComboBox
Set mdcbCombo.oComboBox = Me.cboData
End Sub
Private Sub mdcbCombo_ItemAdded(sItem As String, fCancel As Boolean)
Dim iItem As Long
If LenB(sItem) = 0 Then
fCancel = True
Exit Sub
End If
For iItem = 1 To Me.cboData.ListCount
If Me.cboData.List(iItem) = sItem Then
fCancel = True
Exit Sub
End If
Next iItem
End Sub
Private Sub btnAdd_Click()
Dim sItem As String
sItem = Me.cboData.Text
AddDataItem sItem
End Sub
Private Sub AddDataItem(sItem As String)
Dim fCancel As Boolean
fCancel = False
RaiseEvent ItemAdded(sItem, fCancel)
If Not fCancel Then Me.cboData.AddItem (sItem)
End Sub
You cannot raise an event outside the classes file level.
Add a routine like this inside "DataComboBox1" to allow you to raise the event externally.
Public Sub OnItemAdded(sItem As String, fCancel As Boolean)
RaiseEvent ItemAdded(sItem, fCancel)
End Sub
Then call the OnItemAdded with the current object.
Example...
Private WithEvents mdcbCombo As DataComboBox
...
mdcbCombo.OnItemAdded(sItem, fCancel)