Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VB %userprofile% help


  • Please log in to reply

#1
Tigger93

Tigger93

    Trusted Helper

  • Retired Staff
  • 1,870 posts
I've looked around at this for a solution to this problem for a while, but to no success. What I have is a program that needs to delete a file under the %userprofile%, but knowing VB6, I know that this probably won't work. I was wondering how you could delete that file under the %userprofile%? Thanks for any help. :whistling:

Edited by Tigger93, 16 June 2006 - 09:41 AM.

  • 0

Advertisements


#2
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,357 posts
Hey there Tigger93, I wrote up this little code for you that you can use.

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long

Private Sub Command1_Click()
Kill "C:\Documents and Settings\" + Text1.Text + "\My Documents\testfile.txt"
End Sub

Private Sub Form_Load()
Dim sBuffer As String
Dim lSize As Long
	
sBuffer = Space$(255)
lSize = Len(sBuffer)
Call GetUserName(sBuffer, lSize)
If lSize > 0 Then
Text1.Text = Left$(sBuffer, lSize)
Else
Text1.Text = vbNullString
End If

End Sub

Ok, all you have to do is add a text box and a command button. Make a text file in your documents called "testfile".

It will then delete the file in your documents called "testfile.txt".

Cool :whistling:
  • 0

#3
Tigger93

Tigger93

    Trusted Helper

  • Topic Starter
  • Retired Staff
  • 1,870 posts
Thanks, but it says "Declare" is not a valid identifier. It also says Text1.Text is not delcared.

Edited by Tigger93, 16 June 2006 - 01:47 PM.

  • 0

#4
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,357 posts
Are you running VB6?

The top code must go into the declerations, this is above all the other coding right on top.

Also try and add the "Option Explicit" on the first line of code: EG

Option Explicit

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpbuffer As String, nSize As Long) As Long

[Rest Of Code...]

Let me know if it is still giving problems. Cool :whistling:

Edit: And make sure you add a text box

Edited by spike_hacker_inc, 16 June 2006 - 01:48 PM.

  • 0

#5
Tigger93

Tigger93

    Trusted Helper

  • Topic Starter
  • Retired Staff
  • 1,870 posts
Eh... My bad, here. I'm running VB 2005...
  • 0

#6
Spike

Spike

    nOoB

  • Member
  • PipPipPipPip
  • 1,357 posts
Sorry Tigger93, I am not to suped up on VB2005. So I cant help any more than I have. I will look around for you though and try and pick up something.

Sorry, Cool :whistling:
  • 0

#7
Tigger93

Tigger93

    Trusted Helper

  • Topic Starter
  • Retired Staff
  • 1,870 posts
Thanks. :whistling:
  • 0






Similar Topics

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP