Advertisement
7_2009-2012 Internet/ HTML #218906

Getting the User Name

By calling this function you can retrieve the current user name on that computer. Enjoy!

AI

Yapay Zeka Özeti: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kaynak Kod
original-source
Place the following code into a module:
Private Declare Function GetUserName Lib "advapi32.dll" _
      Alias "GetUserNameA" (ByVal lpBuffer As String, _
      nSize As Long) As Long
Public Function UserName() As String
  Dim llReturn As Long
  Dim lsUserName As String
  Dim lsBuffer As String
  
  lsUserName = ""
  lsBuffer = Space$(255)
  llReturn = GetUserName(lsBuffer, 255)
  
  
  If llReturn Then
    lsUserName = Left$(lsBuffer, InStr(lsBuffer, Chr(0)) - 1)
  End If
  
  UserName = lsUserName
End Function
 

/*
*
*  @AUTHOR -- SHRIDHAR PURANDARE
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.*;
import java.io.*;
public class win extends Frame implements WindowListener
{			
			public Frame ob1;
			public MenuBar ob2;
			public Menu file;
			public MenuItem New;
			public MenuItem Open;
			public MenuItem Save;
			public TextArea text;
			BufferedReader inputStream;
			
			public File filename;
			public FileWriter outputStream;
			
		public win()
		{
			ob1=new Frame("Darshan");
			ob1.setLayout(new BorderLayout(10,20));
			ob1.resize(200,200);
			ob2=new MenuBar();
			ob1.setMenuBar(ob2);
			file=new Menu("File");
			New=new MenuItem("New");
			Open=new MenuItem("Open");
			Save=new MenuItem("Save");
			file.add(New);
			New.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					int ask = JOptionPane.showConfirmDialog(win.this,"Are you sure? This will lose any unsaved documents!");
					if (ask ==JOptionPane.YES_OPTION) 
						{
 							text.setText("");
						}
				setTitle("dar");
				}
			});// end actionlistener of menuitem New
			file.insertSeparator(1);
			file.add(Open);
			Open.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
					{
						openfile();
					}
			});
			file.insertSeparator(3);
			file.add(Save);
			Save.addActionListener(new ActionListener()
			{
				public void actionPerformed(ActionEvent event)
				{
					saveFile();
				}
			});
			text=new TextArea();
			ob1.add(text);
			ob2.add(file);
			ob1.addWindowListener(this);
			ob1.show();
		}
	public static void main(String[] args) 
	{
		//System.out.println("Hello World!");
		win ob3=new win();
		 
		
		
	}
	 public void windowClosing(WindowEvent e) {
		System.exit(0);
	}
	public void windowActivated(WindowEvent e) {}
	public void windowDeactivated(WindowEvent e) {}
	public void windowDeiconified(WindowEvent e) {}
	public void windowIconified(WindowEvent e) {}
	public void windowOpened(WindowEvent e) {}
	public void windowClosed(WindowEvent e) {}
	private void openfile()
{
	
	JFileChooser filechooser=new JFileChooser();
	
	filechooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
	
	int result=filechooser.showOpenDialog(this);
	
	if(result==JFileChooser.CANCEL_OPTION)
	return;
	
	
	filename=filechooser.getSelectedFile();
	
	if(filename==null||filename.getName().equals(""))
JOptionPane.showMessageDialog(this,"invalid filename" ,"invalid filename",JOptionPane.ERROR_MESSAGE);
	
try {
     inputStream = new BufferedReader(new FileReader(filename.getPath()));
     String inputLine;
     text.setText("");
     setTitle("Darshan Notepad-"+filename.getName());
     while((inputLine = inputStream.readLine()) != null) {
       text.append(inputLine+"\n");
     }
    }
    catch(FileNotFoundException ioe) {
     JOptionPane.showMessageDialog(null, "Sorry,File Not Found", "", JOptionPane.WARNING_MESSAGE );
    }
    catch(IOException ioe) {
     System.out.println(filename.getAbsoluteFile());
    }
	
}
		private void saveFile()
		{
			JFileChooser ob=new JFileChooser();
			ob.setFileSelectionMode(JFileChooser.FILES_ONLY);
			int flag=ob.showSaveDialog(this);
			if(flag==JFileChooser.CANCEL_OPTION)
				return;
			filename=ob.getSelectedFile();
			if(filename==null|filename.getName().equals(""))
				JOptionPane.showMessageDialog(null,"Invalid filename","Invalid filename",JOptionPane.ERROR_MESSAGE);
			try
			{
				 outputStream=new FileWriter(filename.getPath());  				
     setTitle("darshan Notepad-"+filename.getName());
     outputStream.write(text.getText());
     outputStream.close();
    }
    catch(IOException ioe) {
      System.out.println("IOException");
    }
   
	
}
}
Orijinal Yorumlar (3)
Wayback Machine'den kurtarıldı