Reset NT password with ‘User Must Change Password’

Reset NT password with ‘User Must Change Password’

Question:
We are trying to reset the NT password using structure USER_INFO_1003. Everything worked fine. Then we also needed to set ‘User Must Change Password at Next Logon’ option. There is no structure just to change that. What I can find is that the only structure I can use is USER_INFO_3.This means that I have to user NetUserGetInfo() API to get all the user info using USER_INFO_3and then use NetUserSetInfo() API to reset everything back except ‘usri3_password_expired’value. This seems like a lot of work just to change one data value. On top of everything, I haven’t been able to get this to work using both APIs. I get an error code 87: invalid parameter value. I am using VB6 for this.

Answer:
It may be a lot of work, but it is the way you will have to do it. The following will reset the “Test guest account” to force a password change on the next logon. Note that this will work on a LOCAL machine. If you want to do it remotely, you must pass the Server name to the function.

IN FORM:Private Sub Command1_Click()   Dim p_strUserName          As String      p_strUserName = "Test guest account"      If Module1.MustChangePassword(p_strUserName) = True Then      MsgBox "Successfully set 'Must Change Password' for user '" & _         p_strUserName & "'."   Else      MsgBox "Failed setting 'Must Change Password' for user '" & _         p_strUserName & "'."   End If   End SubIN BAS or CLS file:Option ExplicitPublic Declare Sub CopyMem Lib "kernel32" Alias _   "RtlMoveMemory" (pTo As Any, pFrom As Any, _   ByVal lCount As Long)Private Declare Function NetApiBufferFree _   Lib "netapi32.dll" _   (ByVal lngPtrBuffer As Long) As LongPrivate Declare Function NetUserSetInfo _   Lib "netapi32" _   (psServer As Byte, _    psUser As Byte, _    ByVal lLevel As Long, _    ByVal pPtrBuffer As Long, _    ParmErr As Long) As LongPrivate Declare Function NetUserGetInfo _   Lib "netapi32" _   (ServerName As Byte, _    UserName As Byte, _    ByVal Level As Long, _    lpBuffer As Long) As LongPrivate Const NERR_Success As Long = 0&Private Const UserInfo3 As Long = 3&Private Type USER_INFO_3_API   usri3_name              As Long   usri3_password          As Long   usri3_password_age      As Long   usri3_priv              As Long   usri3_home_dir          As Long   usri3_comment           As Long   usri3_flags             As Long   usri3_script_path       As Long   usri3_auth_flags        As Long   usri3_full_name         As Long   usri3_usr_comment       As Long   usri3_parms             As Long   usri3_workstations      As Long   usri3_lastlogon         As Long   usri3_lastlogoff        As Long   usri3_acct_expires      As Long   usri3_max_storage       As Long   usri3_units_per_week    As Long   usri3_logon_hours       As Long   usri3_bad_pw_count      As Long   usri3_num_logons        As Long   usri3_logon_server      As Long   usri3_country_code      As Long   usri3_code_page         As Long   usri3_user_id           As Long   usri3_primary_group_id  As Long   usri3_profile           As Long   usri3_home_dir_drive    As Long   usri3_password_expired  As LongEnd TypePublic Function MustChangePassword(ByVal xi_strUserName As String) As Boolean   Dim p_typUserInfo3API   As USER_INFO_3_API   Dim p_bytSvrName()      As Byte   Dim p_bytUserName()     As Byte   Dim p_strServerName     As String   Dim p_lngBuffer         As Long   Dim p_lngParmErr        As Long   Dim p_lngRtn            As Long      ' ------------------------------------------   ' Convert the server name to byte array   ' ------------------------------------------   p_strServerName = vbNullChar   p_bytSvrName = p_strServerName      ' ------------------------------------------   ' Convert the user name to a byte array   ' ------------------------------------------   If Len(Trim$(xi_strUserName)) = 0 Then      Exit Function 'Handle the error   Else      p_bytUserName = xi_strUserName & vbNullChar   End If      ' ------------------------------------------   ' Get the current info   ' ------------------------------------------   p_lngRtn = NetUserGetInfo(p_bytSvrName(0), _                             p_bytUserName(0), _                             UserInfo3, _                             p_lngBuffer)   If p_lngRtn = NERR_Success Then      CopyMem p_typUserInfo3API, _              ByVal p_lngBuffer, _              Len(p_typUserInfo3API)   Else      MsgBox "Error Number: " & p_lngRtn   End If      ' ------------------------------------------   ' Set the current info   ' ------------------------------------------   p_typUserInfo3API.usri3_password_expired = 1   p_lngBuffer = VarPtr(p_typUserInfo3API)      p_lngRtn = NetUserSetInfo(p_bytSvrName(0), _                             p_bytUserName(0), _                             UserInfo3, _                             p_lngBuffer, _                             p_lngParmErr)   If p_lngRtn = NERR_Success Then      CopyMem p_typUserInfo3API, _              ByVal p_lngBuffer, _              Len(p_typUserInfo3API)      MustChangePassword = True   Else      MsgBox "Error Number: " & p_lngRtn   End If         ' ------------------------------------------   ' Clear the buffer   ' ------------------------------------------   If p_lngBuffer Then      NetApiBufferFree p_lngBuffer   End If      End Function
devx-admin

devx-admin

Share the Post:
Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023,

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed

Poland Energy Future

Westinghouse Builds Polish Power Plant

Westinghouse Electric Company and Bechtel have come together to establish a formal partnership in order to design and construct Poland’s inaugural nuclear power plant at the Lubiatowo-Kopalino site in Pomerania.

EV Labor Market

EV Industry Hurting For Skilled Labor

The United Auto Workers strike has highlighted the anticipated change towards a future dominated by electric vehicles (EVs), a shift which numerous people think will result in job losses. However,

Soaring EV Quotas

Soaring EV Quotas Spark Battle Against Time

Automakers are still expected to meet stringent electric vehicle (EV) sales quotas, despite the delayed ban on new petrol and diesel cars. Starting January 2023, more than one-fifth of automobiles

Affordable Electric Revolution

Tesla Rivals Make Bold Moves

Tesla, a name synonymous with EVs, has consistently been at the forefront of the automotive industry’s electric revolution. The products that Elon Musk has developed are at the forefront because

Sunsets' Technique

Inside the Climate Battle: Make Sunsets’ Technique

On February 12, 2023, Luke Iseman and Andrew Song from the solar geoengineering firm Make Sunsets showcased their technique for injecting sulfur dioxide (SO₂) into the stratosphere as a means

AI Adherence Prediction

AI Algorithm Predicts Treatment Adherence

Swoop, a prominent consumer health data company, has unveiled a cutting-edge algorithm capable of predicting adherence to treatment in people with Multiple Sclerosis (MS) and other health conditions. Utilizing artificial

Personalized UX

Here’s Why You Need to Use JavaScript and Cookies

In today’s increasingly digital world, websites often rely on JavaScript and cookies to provide users with a more seamless and personalized browsing experience. These key components allow websites to display

Geoengineering Methods

Scientists Dimming the Sun: It’s a Good Thing

Scientists at the University of Bern have been exploring geoengineering methods that could potentially slow down the melting of the West Antarctic ice sheet by reducing sunlight exposure. Among these

why startups succeed

The Top Reasons Why Startups Succeed

Everyone hears the stories. Apple was started in a garage. Musk slept in a rented office space while he was creating PayPal with his brother. Facebook was coded by a

Bold Evolution

Intel’s Bold Comeback

Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as opposed to the 176% return

Semiconductor market

Semiconductor Slump: Rebound on the Horizon

In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024 approaches, the industry seems to

Elevated Content Deals

Elevate Your Content Creation with Amazing Deals

The latest Tech Deals cater to creators of different levels and budgets, featuring a variety of computer accessories and tools designed specifically for content creation. Enhance your technological setup with

Learn Web Security

An Easy Way to Learn Web Security

The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security. These carefully designed learning courses

Military Drones Revolution

Military Drones: New Mobile Command Centers

The Air Force Special Operations Command (AFSOC) is currently working on a pioneering project that aims to transform MQ-9 Reaper drones into mobile command centers to better manage smaller unmanned

Tech Partnership

US and Vietnam: The Next Tech Leaders?

The US and Vietnam have entered into a series of multi-billion-dollar business deals, marking a significant leap forward in their cooperation in vital sectors like artificial intelligence (AI), semiconductors, and

Huge Savings

Score Massive Savings on Portable Gaming

This week in tech bargains, a well-known firm has considerably reduced the price of its portable gaming device, cutting costs by as much as 20 percent, which matches the lowest

Cloudfare Protection

Unbreakable: Cloudflare One Data Protection Suite

Recently, Cloudflare introduced its One Data Protection Suite, an extensive collection of sophisticated security tools designed to protect data in various environments, including web, private, and SaaS applications. The suite

Drone Revolution

Cool Drone Tech Unveiled at London Event

At the DSEI defense event in London, Israeli defense firms exhibited cutting-edge drone technology featuring vertical-takeoff-and-landing (VTOL) abilities while launching two innovative systems that have already been acquired by clients.

2D Semiconductor Revolution

Disrupting Electronics with 2D Semiconductors

The rapid development in electronic devices has created an increasing demand for advanced semiconductors. While silicon has traditionally been the go-to material for such applications, it suffers from certain limitations.

Cisco Growth

Cisco Cuts Jobs To Optimize Growth

Tech giant Cisco Systems Inc. recently unveiled plans to reduce its workforce in two Californian cities, with the goal of optimizing the company’s cost structure. The company has decided to

FAA Authorization

FAA Approves Drone Deliveries

In a significant development for the US drone industry, drone delivery company Zipline has gained Federal Aviation Administration (FAA) authorization, permitting them to operate drones beyond the visual line of

Mortgage Rate Challenges

Prop-Tech Firms Face Mortgage Rate Challenges

The surge in mortgage rates and a subsequent decrease in home buying have presented challenges for prop-tech firms like Divvy Homes, a rent-to-own start-up company. With a previous valuation of

Lighthouse Updates

Microsoft 365 Lighthouse: Powerful Updates

Microsoft has introduced a new update to Microsoft 365 Lighthouse, which includes support for alerts and notifications. This update is designed to give Managed Service Providers (MSPs) increased control and

Website Lock

Mysterious Website Blockage Sparks Concern

Recently, visitors of a well-known resource website encountered a message blocking their access, resulting in disappointment and frustration among its users. While the reason for this limitation remains uncertain, specialists