|
Thanks Tim, that will work for me. That program is going to save me from so many headaches.
|
|
|
|
|
Good... the power of a community working together...
|
|
|
|
|
Ok, I almost have it working, except I'm now get a NullReferenceException error (Object not set to an instance of an object) on the line marked with a "-->". The error is directly following this paragraph, and my sub procedure is below the error. I call the sub like this: GetPrinters("name-of-server"). If you could help me out, I'd really appreciate it.
Error details:
<br />
System.NullReferenceException was unhandled<br />
Message="Object reference not set to an instance of an object."<br />
Source="ResHelp Troubleshooter"<br />
StackTrace:<br />
at ResHelp.frmAddPrinter.GetPrinters(String strServer) in C:\Users\adamb\Desktop\ResHelp Troubleshooter\ResHelp Troubleshooter\frmAddPrinter.vb:line 68<br />
at ResHelp.frmAddPrinter.lbxServer_SelectedIndexChanged(Object sender, EventArgs e) in C:\Users\adamb\Desktop\ResHelp Troubleshooter\ResHelp Troubleshooter\frmAddPrinter.vb:line 80<br />
at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)<br />
at System.Windows.Forms.ListBox.WmReflectCommand(Message& m)<br />
at System.Windows.Forms.ListBox.WndProc(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br />
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br />
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)<br />
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)<br />
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)<br />
at System.Windows.Forms.Control.WmCommand(Message& m)<br />
at System.Windows.Forms.Control.WndProc(Message& m)<br />
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)<br />
at System.Windows.Forms.ContainerControl.WndProc(Message& m)<br />
at System.Windows.Forms.Form.WndProc(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br />
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br />
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)<br />
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)<br />
at System.Windows.Forms.Control.DefWndProc(Message& m)<br />
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)<br />
at System.Windows.Forms.Control.WndProc(Message& m)<br />
at System.Windows.Forms.ListBox.WndProc(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br />
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br />
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br />
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br />
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)<br />
at System.Windows.Forms.Form.ShowDialog()<br />
at ResHelp.frmMain.btnGo_Click(Object sender, EventArgs e) in C:\Users\adamb\Desktop\ResHelp Troubleshooter\ResHelp Troubleshooter\frmMain.vb:line 15<br />
at System.Windows.Forms.Control.OnClick(EventArgs e)<br />
at System.Windows.Forms.Button.OnClick(EventArgs e)<br />
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)<br />
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)<br />
at System.Windows.Forms.Control.WndProc(Message& m)<br />
at System.Windows.Forms.ButtonBase.WndProc(Message& m)<br />
at System.Windows.Forms.Button.WndProc(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br />
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br />
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br />
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br />
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br />
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br />
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)<br />
at System.Windows.Forms.Form.ShowDialog()<br />
at ResHelp.modMain.main() in C:\Users\adamb\Desktop\ResHelp Troubleshooter\ResHelp Troubleshooter\modMain.vb:line 11<br />
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)<br />
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)<br />
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()<br />
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)<br />
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)<br />
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()<br />
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br />
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br />
at System.Threading.ThreadHelper.ThreadStart()<br />
VB Code to the sub procedure:
<br />
Private Sub GetPrinters(ByVal strServer As String)<br />
Try<br />
Dim connection As New ConnectionOptions<br />
connection.Username = Me.txtUsername.Text<br />
connection.Password = Me.txtPassword.Text<br />
connection.Authority = "ntlmdomain:" + My.Settings.Item("domain").ToString<br />
<br />
Dim scope As New ManagementScope("\\" + strServer + "\root\CIMV2", connection)<br />
scope.Connect()<br />
<br />
Dim query As New ObjectQuery("SELECT * FROM Win32_Printer")<br />
<br />
Dim searcher As New ManagementObjectSearcher(scope, query)<br />
<br />
Me.lbxPrinterShare.Items.Clear()<br />
<br />
For Each queryObj As ManagementObject In searcher.Get()<br />
'If Not (queryObj("ShareName").ToString = "''" Or queryObj("ShareName").ToString = "" Or queryObj("ShareName").ToString = Nothing) Then<br />
--> Me.lbxPrinterShare.Items.Add(queryObj("ShareName").ToString)<br />
'End If<br />
Next<br />
Catch err As ManagementException<br />
MessageBox.Show("An error occurred while querying for WMI printer data: " & err.Message)<br />
Catch unauthorizedErr As System.UnauthorizedAccessException<br />
MessageBox.Show("Connection error (user name or password might be incorrect): " & unauthorizedErr.Message)<br />
End Try<br />
End Sub<br />
DotCom
Help Desk Analyst
(programmer on the side)
|
|
|
|
|
Well, I'm not sure...
Normally, I get the 'Name' attribute, but, my code is written to allow the user to select the desired attributes. When I selected 'ShareName', I had no errors.
Have you confirmed that you can get the sharename using the WMICodeCreator?
|
|
|
|
|
Yeah, and the crazy thing is that I can see the list of sharenames in the creator, but when I execute the code (from the creator), it gives an access denied error, and fails.
DotCom
Help Desk Analyst
(programmer on the side)
|
|
|
|
|
Ok, I figured it out. Some printers don't have share names (because they're a local printer, or for some other reason). Those printers that don't have share names would return a null result for their share name, and that is what was causing the error. I changed the query to have a where clause: "WHERE ShareName IS NOT NULL", and that fixed the issue.
|
|
|
|
|
Hi could anyone please advise on how to insert an image from a VB app into an access record in a table.
thanks
ES
|
|
|
|
|
this may help you.
Regards,
Satips.
|
|
|
|
|
I want to design an user interface where i want to change th color of the title bar of form along with the back color of the max and min buttons? how do i do that/
ciacia
|
|
|
|
|
This article might help.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
i think i have made the connection to the database. i need to know how to write the code to add and ID, surname and forename to the database. don't have a clue how to do this. can you help me?
(this is the connection)
Imports System.Data.OleDb
Public Class cust
Public conn As OleDbConnection
Public comm As OleDbCommand
Public dr As OleDbDataReader
Public da As OleDbDataAdapter
Private Sub cust_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
conn = New OleDbConnection 'establishes that conn is a new connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\PCbank.mdb" 'the name of the connection (name of the database on the end)
conn.Open() 'opens the connection
comm = New OleDbCommand 'establishes that comm is a new command
comm.Connection = conn 'the connection for the command is the connection specified
comm.CommandType = CommandType.Text 'the commands are in text
End Sub
|
|
|
|
|
|
well its jst the simple addiing in data base...
here is the code for u..
check it out....and put yr table name wherever specified tablename and make required changes
<code>Imports System
Imports System.data.oledb
Inherits System.Windows.Forms.Form
public class form1
Dim da As New OleDbDataAdapter("select * from tablename", "provider=microsoft.jet.oledb.4.0;data source=|DataDirectory|\PCbank.mdb;")
Dim ds As New DataSet
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim i As Integer
Dim str As String
'under insert button
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Try
cn = New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=GIVE PATH of yr mdb file;")
cn.Open()
cmd = New OleDbCommand("insert into tablename(ID,surname,forename) values('" & (TextBox1.Text) & "','" & (TextBox2.Text) & "','" & (TextBox3.Text) & ")", cn)
i = cmd.ExecuteNonQuery()
MsgBox("record inserted")
Catch ex As Exception
End Try
cn.Close()</code>
|
|
|
|
|
you can use this code also:
Public Function Query(ByVal SQL As String, ByVal OLEDBCon As OleDb.OleDbConnection, ByRef DS As DataSet) As Integer
Dim DA As New OleDb.OleDbDataAdapter(SQL, OLEDBCon)
Query = DA.Fill(DS)
DA = Nothing
End Function
Public Function Execute(ByVal SQL As String, ByVal OLEDBCon As OleDb.OleDbConnection) As Integer
Dim com As New OleDb.OleDbCommand(SQL, OLEDBCon)
com.ExecuteNonQuery()
com = Nothing
End Function
this is your connection string:
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=sample.mdb")
code of your button save:
dim strInsert as string
try
strInsert="Insert into table1 (field1,fields2...) Values('" & txt1 & "','" & txt2 & "'...)"
con.open
Execute(strInsert,con)
MsgBox("Record Saved")
con.close
end try
my code is simple.
Don't block the drive way of all the newbies in programming. )
|
|
|
|
|
I have download copy paste avi file
how to run avi file in vb.net windows application
|
|
|
|
|
Just implement Windows Media Player into your app.
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Hi
How can we capture the incoming net send message in vb.net?
Thanks
vijay
v
|
|
|
|
|
You can't really intercept them without writing your own packet sniffer ad reassembling the traffic yourself.
The other way to do it is to stop the Messenger service that comes with Windows and write your own replacement for it, taking over the TCP/IP port that it normally listens to.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
I have an application that closes all IE windows that have "MKR" string in the address when the application closes. The problem is that explorer.exe is still listed in the processes. How do I get rid of the process when I close the application?
SR
|
|
|
|
|
You do know that explorer.exe is the process that give you your desktop, right? Why would you want to stop that?
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
The EXE you should look for is iexplore.exe.
Shreekar
|
|
|
|
|
Hi,
I am trying to execute the the function "RegSetKeySecurity" from advapi32.dll in VB Script.
for creating the object i am using wshAPIToolkitObject but i am getting the error...
"WScript.CreateObject: Could not locate automation class named "wshAPIToolkitObject.ucATO"
code :
Set oATO = WScript.CreateObject("wshAPIToolkitObject.ucATO")
lResult = oATO.CallAPI("advapi32.dll", "RegSetKeySecurity", hKey, SecurityInformation, pSecurityDescriptor )
please help me...do i need to have some dlls ?
or i need to register some dlls ?
|
|
|
|
|
It would appear that you either don't have this library installed (it's not part of Windows) or you do have it and it's not registered properly (use REGSVR32).
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
can anyone tell me how to connect to an access database and then add a feild to that database.
any help with this would be greatly appreciated as i literally don't have a clue how to do it.
|
|
|
|
|
what are you using ? adodb ? adodc ?
adding field/column ? why dont you make it directly in access ? or did you mean insert value of your table's fields ?
you can use sql - INSERT command to insert value of fields
and ALTER for add and drop column...
if you're using adodb.. here is the connect function
<br />
Function connect() As Boolean<br />
Dim strConnect As String<br />
connect = False<br />
On Error GoTo errHandler<br />
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\dbpakar.mdb;"<br />
Set conn = New ADODB.Connection<br />
With conn<br />
.CursorLocation = adUseClient<br />
.Open strConnect<br />
End With<br />
connect = True<br />
Exit Function<br />
errHandler: Debug.Print "ERROR! error number: " & Err.Number & ", Description: " & Err.Description<br />
End Function<br />
dont forget to declare the conn , e.g
<br />
Public connVP As ADODB.Connection<br />
if you're using adodc, then just set the adodc's property.
sorry if this isn't the answer that you're looking for- i misunderstood it then..
Practicing
|
|
|
|
|