Skip to main content

Posts

Showing posts from July, 2010

How to Hide File using VB.Net

Private Sub HideFile(ByVal strFilePath As String) Try Dim strFInfo As New FileInfo(strFilePath) strFInfo.Attributes = FileAttributes.Hidden MessageBox.Show("Successfully Applied.") Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub

Create Service on Remote Machine

Private Sub CrateService(ByVal strComputer As String) Dim objWMIService, colServiceList, objService, errReturn, objSWbemLocator Const OWN_PROCESS = 16 Const NOT_INTERACTIVE = False Const NORMAL_ERROR_CONTROL = 2 Dim strName, strDisplay, strPath As String strName = txtName.Text strDisplay = txtDisplay.Text strPath = txtPath.Text Try objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") If (strComputer = Environment.MachineName.ToString) Then objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2") Else objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", strTargetUser, strTargetPwd) End If objWMIService.Security_.ImpersonationLevel = 3 objService = objWMIService.Get("Win32_BaseService") errReturn = objService.Cr

Change IE Proxy on Remote Machine

Private Sub ChangeProxy(ByVal IP As String, ByVal Proxy As Boolean, ByVal strAddress As String, ByVal ByPass As Boolean) Dim strComputer Dim strUserName Dim strPassword Dim objLocator Dim objService Dim objRegistry Dim strKeyPath, strValueName, strValue As String Dim dwValue As Integer Const HKEY_CURRENT_USER = &H80000001 strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" strComputer = IP strUserName = UserName strPassword = Password Try objLocator = CreateObject("WbemScripting.SWbemLocator") If (IP = System.Environment.MachineName) Then objService = objLocator.ConnectServer(strComputer, "Root\Default") Else objService = objLocator.ConnectServer(strComputer, "Root\Default", strUserName, strPassword) End If ob

Kill Process on Remote Machine

Private Sub ProcessKill(ByVal strIP As String, ByVal PID As Integer) Dim query As Management.ManagementObjectSearcher Dim queryCollection As Management.ManagementObjectCollection Dim management_object1 As Management.ManagementObject Dim msc As Management.ManagementScope Dim co As New Management.ConnectionOptions co.Username = UserName co.Password = Password If (strIP = Environment.MachineName.ToString) Then msc = New Management.ManagementScope("\\" & strIP & "\root\cimv2") Else msc = New Management.ManagementScope("\\" & strIP & "\root\cimv2", co) End If Dim id As String = PID Dim query_command As String = "SELECT * FROM Win32_Process where ProcessId=" & id Dim select_query As Management.SelectQuery = New Management.SelectQuery(query_command) Try query = New Manage

Ping Network Computer in VB.Net

"Ping" is very basic utility for every network programmer. Here we will discuss ping a computer in Network using VB.Net. We have two methods for pinging a computer. Method 1: Here we will use VB.Net NetworkInformation NameSpace. Public Sub PingStatus(ByVal strComputer As String) Dim pingSender As Ping = New Ping() Dim options As PingOptions = New PingOptions() options.DontFragment = True 'Create a buffer of 32 bytes of data to be transmitted Dim data As String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Dim buffer As Byte() = Encoding.ASCII.GetBytes(data) Dim timeout As Integer = 120 Dim reply As PingReply = pingSender.Send(strComputer, timeout, buffer, options) If (reply.Status = IPStatus.Success) Then MessageBox.Show("Ping Successed.") Else MessageBox.Show("Ping Faild.") End If End Sub Method 2: Here we are using .Net inbuil

Free Disk Space on Remote Computer

Public Sub GetFreeDiskSpace(ByVal strComputer As String, ByVal strUserName As String, ByVal strPwd As String) Dim query As Management.ManagementObjectSearcher Dim queryCollection As Management.ManagementObjectCollection Dim management_object1 As Management.ManagementObject Dim msc As Management.ManagementScope If (strComputer = System.Environment.MachineName) Then msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2") Else Dim co As New Management.ConnectionOptions co.Username = strUserName co.Password = strPwd msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2", co) End If Dim query_command As String = "SELECT * FROM Win32_LogicalDisk" Dim select_query As Management.SelectQuery = New Management.SelectQuery(query_command) Try quer

Get Installed Printer on Netwrok

Public Sub NetworkInstalledPrinter(ByVal strComputer As String, ByVal strUserName As String, ByVal strPwd As String) Try Dim Query As Management.ObjectQuery = New System.Management.ObjectQuery("SELECT * FROM Win32_Printer") Dim moSearcher As Management.ManagementObjectSearcher = New System.Management.ManagementObjectSearcher(Query) Dim moc As Management.ManagementObjectCollection = moSearcher.Get() For Each mo As Management.ManagementObject In moc Dim Pdc As Management.PropertyDataCollection = mo.Properties For Each pd As Management.PropertyData In Pdc Try If (CType(mo("Network"), Boolean)) Then Dim strName As String strName = CType(mo(pd.Name), String) If (strName.StartsWith("\\")) Then MessageBox.Show(str

Get Installed Printer List on Remote Machine

Public Sub RemoteInstalledPrinter(ByVal strComputer As String, ByVal strUserName As String, ByVal strPwd As String) Dim query As Management.ManagementObjectSearcher Dim queryCollection As Management.ManagementObjectCollection Dim management_object1 As Management.ManagementObject Dim msc As Management.ManagementScope If (strComputer = System.Environment.MachineName) Then msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2") Else Dim co As New Management.ConnectionOptions co.Username = strUserName co.Password = strPwd msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2", co) End If Dim query_command As String = "SELECT * FROM Win32_Printer" Dim select_query As Management.SelectQuery = New Management.SelectQuery(query_command) Try q

Installed Software List on Remote Machine using Registry

Public Sub SoftwareInformationRegistry(ByVal strComputer As String, ByVal strUserName As String, ByVal strPwd As String) Dim objLocator, objService, objRegistry, arrIdentityCode, strIdentityCode, objShell Dim objFSO, objTextFile Dim strRegIdentityCodes As String objLocator = CreateObject("WbemScripting.SWbemLocator") Try If (strComputer = System.Environment.MachineName) Then objService = objLocator.ConnectServer(strComputer, "Root\Default") Else objService = objLocator.ConnectServer(strComputer, "Root\Default", strUserName, strPwd) End If objService.Security_.impersonationlevel = 3 objRegistry = objService.Get("StdRegProv") Catch ex As Exception MessageBox.Show("Kindly Enter Domain Credential.", "Remote Software Install", MessageBoxButtons.OK, MessageBoxIcon.Exclamat

Installed Software List on Remote Machine using WMI

Public Sub SoftwareInformationVBS(ByVal strComputer As String, ByVal strUserName As String, ByVal strPwd As String) Dim objWMIService, objFSO, objTextFile, colSoftware, objSoftware, objSWbemLocator Try objFSO = CreateObject("Scripting.FileSystemObject") objTextFile = objFSO.CreateTextFile("c:\software.txt", True) objSWbemLocator = CreateObject("WbemScripting.SWbemLocator") If (strComputer = Environment.MachineName.ToString) Then objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2") Else objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", strUserName, strPwd) End If objWMIService.Security_.ImpersonationLevel = 3 colSoftware = objWMIService.ExecQuery("Select * from Win32_Product") objTextFile.WriteLine("Caption" &