用EXCEL得出本機用戶名及IP

Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, _

nSize As Long) As Long

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _

(ByVal lpBuffer As String, _

nSize As Long) As Long

Sub Get_Computer_Name()

'獲得當前的機器名稱

Dim Comp_Name_B As String * 255

Dim Comp_Name As String

GetComputerName Comp_Name_B, Len(Comp_Name_B)

Comp_Name = Left(Comp_Name_B, InStr(Comp_Name_B, Chr(0)))

MsgBox "您正在使用的這台機器名爲:" & Comp_Name, vbOKOnly, "WINAK"

End Sub

Sub Get_User_Name()

'獲得當前用戶名

Dim lpBuff As String * 25

Dim ret As Long, UserName As String

ret = GetUserName(lpBuff, 25)

UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)

MsgBox "當前用戶名:" & UserName, vbOKOnly, "WINAK"

End Sub

--------------------------------------------------------------------------------

獲取IP地址

1、局域網內IP地址及網卡MAC地址

Sub IP()

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set IPConfigSet = objWMIService.ExecQuery _

("Select * from Win32_NetworkAdapterConfiguration ")

For Each IPConfig In IPConfigSet

On Error Resume Next

s = ""

s = s & "Description: " & IPConfig.Description & vbCrLf

ss = ""

For i = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)

ss = ss & IPConfig.IPAddress(i) & " "

Next

s = s & "IPAddress: " & ss & vbCrLf

s = s & "MACAddress: " & IPConfig.MACAddress & vbCrLf

MsgBox s

Next

End Sub

2、外網IP地址

Sub Sample4()

Dim WSH, wExec, sCmd As String, Result As String, tmp, buf As String, i As Long

Set WSH = CreateObject("WScript.Shell")

sCmd = "nslookup baidu.com"

Set wExec = WSH.Exec("%ComSpec% /c " & sCmd)

Do While wExec.Status = 0

DoEvents

Loop

Result = wExec.StdOut.ReadAll

tmp = Split(Result, vbCrLf)

For i = 0 To UBound(tmp)

If Left(tmp(i), 5) = "Name:" Then

buf = tmp(i + 1)

End If

Next i

MsgBox buf

Set wExec = Nothing

Set WSH = Nothing

End Sub

--------------------------------------------------------------------------------

獲取計算機名也可用

MsgBox Environ("Computername")

--------------------------------------------------------------------------------

Sub 獲得計算機名和使用者名()

Dim myStr As String

Set myWshNw = CreateObject("Wscript.Network")

myStr = myStr & "計算機名稱 = " & myWshNw.ComputerName & vbCrLf

myStr = myStr & "使用者姓名 = " & myWshNw.UserName & vbCrLf

MsgBox myStr

End Sub

--------------------------------------------------------------------------------

獲取IP方法

Private Sub CommandButton2_Click()

GetMyIP

End Sub

Private Sub CommandButton3_Click()

test

End Sub

Private Sub CommandButton4_Click()

TestingFunction

End Sub

Private Sub CommandButton5_Click()

ip_REMOTECOMPUTER

End Sub

Private Sub CommandButton6_Click()

exeIpconfig

End Sub

Private Sub CommandButton7_Click()

ipconfigAll

End Sub

Delphi 快速獲取本機的IP地址-DLEPHI
  朋友們在用Delphi編程序的時候,常常碰到需要在程序中獲取自己的IP地址的情況。在以往的版本中,可以通過編寫一段代碼或函數實現這一功能。但有了Delphi 7,這個工作可以更簡化了。利用控件只需一句代碼,就可以...查看完整版>>Delphi 快速獲取本機的IP地址-DLEPHI
 
java獲取本機的ip地址
可以用如下代碼: InetAddress inet = InetAddress.getLocalHost(); System.out.println("本機的ip=" + inet.getHostAddress());在window下面可以工作。在Linux下返回127.0.0.1。主要是在linux下...查看完整版>>java獲取本機的ip地址
 
c#.net如何獲取本機ip
    using System;  using System.Collections;  using System.ComponentModel;  using System.Data;  using System.Drawing;  using System.Web;  using System.Web.SessionState;  using System...查看完整版>>c#.net如何獲取本機ip
 
獲取本機的IP地址代碼
看到了就收藏一下。#include<stdio.h>#include<winsock2.h>#pragma comment(lib,"ws2_32")//void CheckIP(void);/* 定義CheckIP()函數,用于獲取本機IP地址 */void CheckIP(void) { WSADATA...查看完整版>>獲取本機的IP地址代碼
 
java獲取本機的ip地址
可以用如下代碼: InetAddress inet = InetAddress.getLocalHost(); System.out.println("本機的ip=" + inet.getHostAddress());在window下面可以工作。在linux下返回127.0.0.1。主要...查看完整版>>java獲取本機的ip地址
 
列出本機所有的Ip
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,winsock;type TForm1 = class(TForm) Button1: TButton; procedure Button1Cli...查看完整版>>列出本機所有的Ip
 
獲得本機IP和名稱
//iplabel.javaimport java.net.*;import java.awt.*;import javax.swing.*; public class iplabel{JFrame frame;JLabel label1,label2;JPanel panel;String ip,address; public void getip(){try{InetAddress addr ...查看完整版>>獲得本機IP和名稱
 
Linux下ADSL用戶使用科邁公司的動態域名在本機建站詳解
  1.注冊  用戶注冊  二級免費域名申請  2. 下載  點擊這裏下載  3. 安裝  安裝說明  下載的是壓縮文件。在系統裏建立一個目錄,如/local/comexe,把下載的文件解壓到這個目錄即可。  Linux平台的...查看完整版>>Linux下ADSL用戶使用科邁公司的動態域名在本機建站詳解
 
普通用戶Excel使用VBA的幾個誤區
  VBA是從流行的Visual Basic編程語言中派生出來的一種面向應用程序的語言,它適用于各種Windows應用程序,可以解決各應用程序的宏語言不統一的問題,今天我們談談Excel中使用VBA的幾個誤區。  1、想通過Excel+v...查看完整版>>普通用戶Excel使用VBA的幾個誤區
 
 
回到王朝網路移動版首頁